Index: src/OFString+JSONValue.m ================================================================== --- src/OFString+JSONValue.m +++ src/OFString+JSONValue.m @@ -355,16 +355,17 @@ } static inline OFNumber* parseNumber(const char *restrict *pointer, const char *stop) { + BOOL isHex = (*pointer + 1 < stop && (*pointer)[1] == 'x'); BOOL hasDecimal = NO; size_t i; OFString *string; OFNumber *number; - for (i = 1; *pointer + i < stop; i++) { + for (i = 0; *pointer + i < stop; i++) { if ((*pointer)[i] == '.') hasDecimal = YES; if ((*pointer)[i] == ' ' || (*pointer)[i] == '\t' || (*pointer)[i] == '\r' || (*pointer)[i] == '\n' || @@ -379,10 +380,13 @@ @try { if (hasDecimal) number = [OFNumber numberWithDouble: [string doubleValue]]; + else if (isHex) + number = [OFNumber numberWithIntMax: + [string hexadecimalValue]]; else number = [OFNumber numberWithIntMax: [string decimalValue]]; } @finally { [string release]; @@ -446,10 +450,11 @@ case '6': case '7': case '8': case '9': case '-': + case '.': return parseNumber(pointer, stop); default: return nil; } } Index: tests/OFJSONTests.m ================================================================== --- tests/OFJSONTests.m +++ tests/OFJSONTests.m @@ -31,26 +31,27 @@ @implementation TestsAppDelegate (JSONTests) - (void)JSONTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *s = @"{\"foo\"\t:'ba\\r', \"x\":/*fooo*/ [7.5\r,null//bar\n" + OFString *s = @"{\"foo\"\t:'ba\\r', \"x\":/*foo*/ [.5\r,0xF,null//bar\n" @",\"foo\",false]}"; OFDictionary *d = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"ba\r", @"x", [OFArray arrayWithObjects: - [OFNumber numberWithFloat: 7.5f], + [OFNumber numberWithFloat: .5f], + [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: NO], nil], nil]; TEST(@"-[JSONValue #1]", [[s JSONValue] isEqual: d]) TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual: - @"{\"foo\":\"ba\\r\",\"x\":[7.5,null,\"foo\",false]}"]) + @"{\"foo\":\"ba\\r\",\"x\":[0.5,15,null,\"foo\",false]}"]) EXPECT_EXCEPTION(@"-[JSONValue #2]", OFInvalidEncodingException, [@"{" JSONValue]) EXPECT_EXCEPTION(@"-[JSONValue #3]", OFInvalidEncodingException, [@"]" JSONValue])