In a JQuery ajax call, when the data type is set to "json", JQuery uses the "eval" function to convert the response from the server into a valid Json object. There are some security concerns with using eval. As mentioned in the post, the alternative to using eval is to use a json parser. The downside is that javascript parsers are not going to be as performant as using eval. An easy way to plugin your parser is to use the dataFilter option in JQuery ajax call. For example:
$.ajax({
type: method,
url: url,
data: data,
dataFilter: function(data) { <<<<<<<<
return jsonParse(data);
},
timeout: 20000,
cache: false,
success: success,
error: error
});
Notice the dataType parameter is omitted since we handle the parsing ourself.
Monday, August 17, 2009
Wednesday, May 27, 2009
Selenium and firefox-3
http://www.spacevatican.org/2008/9/27/selenium-and-firefox-3
Beta-2 fixes this bug.
Beta-2 fixes this bug.
Monday, May 4, 2009
Cleanup in Selenium HTML tests
Selenium is a great testing tool. One drawback when writing HTML based tests using selenium is that there is no support for cleaning up after a test. So, if a test fails it may leave things in an inconsistent state which causes problems for subsequents tests in the suite or even for the same test to run repeatedly. One solution is to have a "special clean up test" that runs after each test. I have been thinking of introducing a cleanup section in a selenium test which is demarcated by the word: "cleanup." This requires changes to how HtmlTestCase parses commands in selenium-testrunner.js. When it encounters the special "cleanup" keyword, the rest of the commands are interpreted as being part of the cleanup portion of the test case. Also, modifications need to be made to the HtmlRunnerTestLoop , so that the testComplete function runs the cleanup portion of the test, before running the next test.
Sunday, January 25, 2009
Sequence Points
Sequence points map between IL (intermediate language) and C# source elements. A statement in C# may be implemented by several IL instructions. Several of these IL instructions may map to a single native instruction. They are essential for supporting source-level debugging as explained here.
NDepend uses sequence points to compute lines of code as explained here.
NCover uses sequence points to determine code coverage.
NDepend uses sequence points to compute lines of code as explained here.
NCover uses sequence points to determine code coverage.
Sunday, January 11, 2009
Cyclomatic complexity - class vs method level? Chidamber & K
Cyclomatic complexity is useful to look at the method level. At the class level it mayb e useful to look at the sum of CC's of all the methods in the class - this is a different measure referred to as Weighted Method per Class.
This is a good article that looks at cyclomatic complexity of methods in a codebase developed using TDD approach.
This article looks at the correlation between defects and complexity measures.
The Chidamber & Kemerer metrics are worth taking a look at:
- WMC: Weighted methods per class
- DIT: Depth of Inheritance Tree
- NOC: Number of Children
- CBO: Coupling between object classes
- RFC: Response for a Class
- LCOM: Lack of cohesion in methods
This is a good article that looks at cyclomatic complexity of methods in a codebase developed using TDD approach.
This article looks at the correlation between defects and complexity measures.
The Chidamber & Kemerer metrics are worth taking a look at:
- WMC: Weighted methods per class
- DIT: Depth of Inheritance Tree
- NOC: Number of Children
- CBO: Coupling between object classes
- RFC: Response for a Class
- LCOM: Lack of cohesion in methods
Sunday, January 4, 2009
RhinoMocks Constraints with IsMatching() using Predicate
var mocks = new MockRepository();
var repository = mocks.StrictMock();
var controller = new AController(repository);
List items = new List {"foo"};
var modelObj = new ModelObj(items);
Predicate compareModelObjs =
delegate(ModelObj m) { return m.Items.AsEnumerable().SequenceEqual(items); }
repository.Expect(r => r.SaveModelObj(null)).Constraints(Is.Matching(compareModelObjs)).Return(true);
mocks.ReplayAll();
controller.Save(items);
mocks.VerifyAll();
Of course, you should probably write an Equals() method on the ModelObj.
var repository = mocks.StrictMock
var controller = new AController(repository);
List
var modelObj = new ModelObj(items);
Predicate
delegate(ModelObj m) { return m.Items.AsEnumerable().SequenceEqual(items); }
repository.Expect(r => r.SaveModelObj(null)).Constraints(Is.Matching(compareModelObjs)).Return(true);
mocks.ReplayAll();
controller.Save(items);
mocks.VerifyAll();
Of course, you should probably write an Equals() method on the ModelObj.
Monday, December 22, 2008
LINQ-to-SQL: DataContext.SubmitChanges() throws ChangeConflictException if NOCOUNT is ON
DataContext.SubmitChanges() will throw a ChangeConflictException if NOCOUNT is on. Use Reflector to look at the code in System.Data.Linq, you will notice that ChangeProcessor.SubmitChanges() method uses the count of the number of rows affected by the SQL statement to determine if updates succeeded. Updates are setup to fail if the row being updated was deleted or modified concurrently by another user. For example, say your update had modified value for column C in table T in the row with primary key PK = 1 from 5 to 6. The update statement constructed by Linq will look something like:
update T set C=6 where PK=1 and C = 5
The update will return 0 rows affected when either the row was deleted by a different user or if the value of C was updated. In either case, LINQ will raise a ChangeConflictException. However, if NOCOUNT is on, then the update statement will always return 0. Hence LINQ throws the ChangeConflictException even if there is no conflict.
update T set C=6 where PK=1 and C = 5
The update will return 0 rows affected when either the row was deleted by a different user or if the value of C was updated. In either case, LINQ will raise a ChangeConflictException. However, if NOCOUNT is on, then the update statement will always return 0. Hence LINQ throws the ChangeConflictException even if there is no conflict.
Subscribe to:
Comments (Atom)