diff options
Diffstat (limited to 'db/json.cpp')
-rw-r--r-- | db/json.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/db/json.cpp b/db/json.cpp index 4a6fad8..b89ff32 100644 --- a/db/json.cpp +++ b/db/json.cpp @@ -258,8 +258,12 @@ namespace mongo { struct numberValue { numberValue( ObjectBuilder &_b ) : b( _b ) {} - void operator() ( double d ) const { - b.back()->append( b.fieldName(), d ); + void operator() ( const char *start, const char *end ) const { + // We re-parse the numeric string here because spirit parsing of strings + // to doubles produces different results from strtod in some cases and + // we want to use strtod to ensure consistency with other string to + // double conversions in our code. + b.back()->append( b.fieldName(), strtod( start, 0 ) ); } ObjectBuilder &b; }; @@ -315,6 +319,14 @@ namespace mongo { ObjectBuilder &b; }; + struct undefinedValue { + undefinedValue( ObjectBuilder &_b ) : b( _b ) {} + void operator() ( const char *start, const char *end ) const { + b.back()->appendUndefined( b.fieldName() ); + } + ObjectBuilder &b; + }; + struct dbrefNS { dbrefNS( ObjectBuilder &_b ) : b( _b ) {} void operator() ( const char *start, const char *end ) const { @@ -454,12 +466,13 @@ namespace mongo { elements = list_p(value, ch_p(',')[arrayNext( self.b )]); value = str[ stringEnd( self.b ) ] | - number | + number[ numberValue( self.b ) ] | integer | array[ arrayEnd( self.b ) ] | lexeme_d[ str_p( "true" ) ][ trueValue( self.b ) ] | lexeme_d[ str_p( "false" ) ][ falseValue( self.b ) ] | lexeme_d[ str_p( "null" ) ][ nullValue( self.b ) ] | + lexeme_d[ str_p( "undefined" ) ][ undefinedValue( self.b ) ] | singleQuoteStr[ stringEnd( self.b ) ] | date[ dateEnd( self.b ) ] | oid[ oidEnd( self.b ) ] | @@ -501,7 +514,7 @@ namespace mongo { // real_p accepts numbers with nonsignificant zero prefixes, which // aren't allowed in JSON. Oh well. - number = strict_real_p[ numberValue( self.b ) ]; + number = strict_real_p; static int_parser<long long, 10, 1, numeric_limits<long long>::digits10 + 1> long_long_p; integer = long_long_p[ intValue(self.b) ]; |