allen58992008 / touchcode

Automatically exported from code.google.com/p/touchcode
0 stars 0 forks source link

CJSONSerializer serializeArray doesn't correctly handle arrays with the same instances in certain places. #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Create an array that contains the same instance somewhere in the middle and
as the final element, e.g.,

    NSString* a = @"a";
    NSArray* array = [NSArray arrayWithObjects:a, @"b", a, nil];

What is the expected output? What do you see instead?

If that array is serialized, it should look like this:

    ["a","b","a"]

but it looks like this:

    ["a""b","a"]

The check to see if the last element of the array is serialized, and this,
if a "," string should be appended or not, is not reliable. "theValue" can
be the same as the last object, even though it isn't the last element in
the array.

This bug is present in revision 162 of the file.

Original issue reported on code.google.com by magnus...@gmail.com on 19 Mar 2009 at 10:22

GoogleCodeExporter commented 8 years ago
Patch attached with test to reproduce the issue and the fix. 
Replaced lastObject test with a counter to do the conditional test against the 
number of elements in the array 
instead.

Original comment by jpedroso@gmail.com on 17 May 2009 at 1:35

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the patch & unit test. Looks good to me.

Original comment by jwight on 17 May 2009 at 1:53