mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Merge branch 'master' of git.10gen.com:/data/gitroot/p
This commit is contained in:
commit
c0c7d99027
23
db/json.cpp
23
db/json.cpp
@ -109,6 +109,9 @@ namespace mongo {
|
||||
case '\"':
|
||||
o = '\"';
|
||||
break;
|
||||
case '\'':
|
||||
o = '\'';
|
||||
break;
|
||||
case '\\':
|
||||
o = '\\';
|
||||
break;
|
||||
@ -419,6 +422,7 @@ public:
|
||||
fieldName >> ':' >> value;
|
||||
fieldName =
|
||||
str[ fieldNameEnd( self.b ) ] |
|
||||
singleQuoteStr[ fieldNameEnd( self.b ) ] |
|
||||
unquotedFieldName[ unquotedFieldNameEnd( self.b ) ];
|
||||
array = ch_p( '[' )[ arrayStart( self.b ) ] >> !elements >> ']';
|
||||
elements = value >> !( ch_p( ',' )[ arrayNext( self.b ) ] >> elements );
|
||||
@ -428,6 +432,7 @@ public:
|
||||
date[ dateEnd( self.b ) ] |
|
||||
regex[ regexEnd( self.b ) ] |
|
||||
str[ stringEnd( self.b ) ] |
|
||||
singleQuoteStr[ stringEnd( self.b ) ] |
|
||||
number |
|
||||
object[ subobjectEnd( self.b ) ] |
|
||||
array[ arrayEnd( self.b ) ] |
|
||||
@ -448,10 +453,26 @@ public:
|
||||
( ch_p( 'u' ) >> ( repeat_p( 4 )[ xdigit_p ][ chU( self.b ) ] ) ) ) ) |
|
||||
ch_p( '\x7f' )[ ch( self.b ) ] |
|
||||
( ~cntrl_p & ~ch_p( '"' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> '"' ];
|
||||
|
||||
singleQuoteStr = lexeme_d[ ch_p( '\'' )[ chClear( self.b ) ] >>
|
||||
*( ( ch_p( '\\' ) >>
|
||||
( ch_p( '\'' )[ chE( self.b ) ] |
|
||||
ch_p( '\\' )[ chE( self.b ) ] |
|
||||
ch_p( '/' )[ chE( self.b ) ] |
|
||||
ch_p( 'b' )[ chE( self.b ) ] |
|
||||
ch_p( 'f' )[ chE( self.b ) ] |
|
||||
ch_p( 'n' )[ chE( self.b ) ] |
|
||||
ch_p( 'r' )[ chE( self.b ) ] |
|
||||
ch_p( 't' )[ chE( self.b ) ] |
|
||||
( ch_p( 'u' ) >> ( repeat_p( 4 )[ xdigit_p ][ chU( self.b ) ] ) ) ) ) |
|
||||
ch_p( '\x7f' )[ ch( self.b ) ] |
|
||||
( ~cntrl_p & ~ch_p( '\'' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> '\'' ];
|
||||
|
||||
// real_p accepts numbers with nonsignificant zero prefixes, which
|
||||
// aren't allowed in JSON. Oh well.
|
||||
number = real_p[ numberValue( self.b ) ];
|
||||
|
||||
// We allow a subset of valid js identifier names here.
|
||||
unquotedFieldName = lexeme_d[ ( alpha_p | ch_p( '$' ) ) >> *( ( alnum_p | ch_p( '$' ) | ch_p( '_' ) ) ) ];
|
||||
|
||||
dbref = dbrefS | dbrefT;
|
||||
@ -495,7 +516,7 @@ public:
|
||||
}
|
||||
rule< ScannerT > object, members, pair, array, elements, value, str, number,
|
||||
dbref, dbrefS, dbrefT, oid, oidS, oidT, bindata, date, dateS, dateT,
|
||||
regex, regexS, regexT, quotedOid, fieldName, unquotedFieldName;
|
||||
regex, regexS, regexT, quotedOid, fieldName, unquotedFieldName, singleQuoteStr;
|
||||
const rule< ScannerT > &start() const {
|
||||
return object;
|
||||
}
|
||||
|
@ -826,6 +826,17 @@ namespace JsonTests {
|
||||
}
|
||||
};
|
||||
|
||||
class SingleQuotes : public Base {
|
||||
virtual BSONObj bson() const {
|
||||
BSONObjBuilder b;
|
||||
b.append( "ab'c\"", "bb\b '\"" );
|
||||
return b.doneAndDecouple();
|
||||
}
|
||||
virtual string json() const {
|
||||
return "{ 'ab\\'c\"' : 'bb\\b \\'\"' }";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace FromJsonTests
|
||||
|
||||
class All : public UnitTest::Suite {
|
||||
@ -896,6 +907,7 @@ namespace JsonTests {
|
||||
add< FromJsonTests::Malformed >();
|
||||
add< FromJsonTests::UnquotedFieldName >();
|
||||
add< FromJsonTests::UnquotedFieldNameDollar >();
|
||||
add< FromJsonTests::SingleQuotes >();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user