Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
873ad336
Commit
873ad336
authored
Sep 02, 2009
by
Jesse Beder
Browse files
Fixed bug with omitted keys/values in a flow map
parent
0d41a7de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
3 deletions
+49
-3
src/exp.h
src/exp.h
+2
-2
src/scanner.cpp
src/scanner.cpp
+1
-1
src/scantoken.cpp
src/scantoken.cpp
+6
-0
yaml-reader/parsertests.cpp
yaml-reader/parsertests.cpp
+36
-0
yaml-reader/tests.cpp
yaml-reader/tests.cpp
+2
-0
yaml-reader/tests.h
yaml-reader/tests.h
+2
-0
No files found.
src/exp.h
View file @
873ad336
...
@@ -37,7 +37,7 @@ namespace YAML
...
@@ -37,7 +37,7 @@ namespace YAML
const
RegEx
Key
=
RegEx
(
'?'
),
const
RegEx
Key
=
RegEx
(
'?'
),
KeyInFlow
=
RegEx
(
'?'
)
+
BlankOrBreak
;
KeyInFlow
=
RegEx
(
'?'
)
+
BlankOrBreak
;
const
RegEx
Value
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
()),
const
RegEx
Value
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
()),
ValueInFlow
=
RegEx
(
':'
)
+
BlankOrBreak
;
ValueInFlow
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
(
",}"
,
REGEX_OR
))
;
const
RegEx
Comment
=
RegEx
(
'#'
);
const
RegEx
Comment
=
RegEx
(
'#'
);
const
RegEx
AnchorEnd
=
RegEx
(
"?:,]}%@`"
,
REGEX_OR
)
||
BlankOrBreak
;
const
RegEx
AnchorEnd
=
RegEx
(
"?:,]}%@`"
,
REGEX_OR
)
||
BlankOrBreak
;
...
@@ -49,7 +49,7 @@ namespace YAML
...
@@ -49,7 +49,7 @@ namespace YAML
const
RegEx
PlainScalar
=
!
(
BlankOrBreak
||
RegEx
(
",[]{}#&*!|>
\'\"
%@`"
,
REGEX_OR
)
||
(
RegEx
(
"-?:"
,
REGEX_OR
)
+
Blank
)),
const
RegEx
PlainScalar
=
!
(
BlankOrBreak
||
RegEx
(
",[]{}#&*!|>
\'\"
%@`"
,
REGEX_OR
)
||
(
RegEx
(
"-?:"
,
REGEX_OR
)
+
Blank
)),
PlainScalarInFlow
=
!
(
BlankOrBreak
||
RegEx
(
"?,[]{}#&*!|>
\'\"
%@`"
,
REGEX_OR
)
||
(
RegEx
(
"-:"
,
REGEX_OR
)
+
Blank
));
PlainScalarInFlow
=
!
(
BlankOrBreak
||
RegEx
(
"?,[]{}#&*!|>
\'\"
%@`"
,
REGEX_OR
)
||
(
RegEx
(
"-:"
,
REGEX_OR
)
+
Blank
));
const
RegEx
EndScalar
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
()),
const
RegEx
EndScalar
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
()),
EndScalarInFlow
=
(
RegEx
(
':'
)
+
BlankOrBreak
)
||
RegEx
(
",?[]{}"
,
REGEX_OR
);
EndScalarInFlow
=
(
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
(
",]}"
,
REGEX_OR
))
)
||
RegEx
(
",?[]{}"
,
REGEX_OR
);
const
RegEx
EscSingleQuote
=
RegEx
(
"
\'\'
"
);
const
RegEx
EscSingleQuote
=
RegEx
(
"
\'\'
"
);
const
RegEx
EscBreak
=
RegEx
(
'\\'
)
+
Break
;
const
RegEx
EscBreak
=
RegEx
(
'\\'
)
+
Break
;
...
...
src/scanner.cpp
View file @
873ad336
...
@@ -104,7 +104,7 @@ namespace YAML
...
@@ -104,7 +104,7 @@ namespace YAML
// *****
// *****
// And now branch based on the next few characters!
// And now branch based on the next few characters!
// *****
// *****
// end of stream
// end of stream
if
(
!
INPUT
)
if
(
!
INPUT
)
return
EndStream
();
return
EndStream
();
...
...
src/scantoken.cpp
View file @
873ad336
...
@@ -181,6 +181,12 @@ namespace YAML
...
@@ -181,6 +181,12 @@ namespace YAML
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
MAP_VALUE
);
throw
ParserException
(
INPUT
.
mark
(),
ErrorMsg
::
MAP_VALUE
);
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
MAP
);
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
MAP
);
}
else
{
// we might have an empty key, so we should add it (as a simple key)
if
(
m_simpleKeyAllowed
)
{
InsertSimpleKey
();
VerifySimpleKey
();
}
}
}
// can only put a simple key here if we're in block context
// can only put a simple key here if we're in block context
...
...
yaml-reader/parsertests.cpp
View file @
873ad336
...
@@ -220,6 +220,42 @@ namespace Test
...
@@ -220,6 +220,42 @@ namespace Test
return
true
;
return
true
;
}
}
bool
FlowMapWithOmittedKey
()
{
std
::
string
input
=
"{: omitted key}"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
std
::
string
output
;
doc
[
YAML
::
Null
]
>>
output
;
if
(
output
!=
"omitted key"
)
return
false
;
return
true
;
}
bool
FlowMapWithOmittedValue
()
{
std
::
string
input
=
"{a: b, c:, d:}"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
std
::
string
output
;
doc
[
"a"
]
>>
output
;
if
(
output
!=
"b"
)
return
false
;
if
(
!
IsNull
(
doc
[
"c"
]))
return
false
;
if
(
!
IsNull
(
doc
[
"d"
]))
return
false
;
return
true
;
}
bool
QuotedSimpleKeys
()
bool
QuotedSimpleKeys
()
{
{
std
::
string
KeyValue
[
3
]
=
{
"
\"
double
\"
: double
\n
"
,
"'single': single
\n
"
,
"plain: plain
\n
"
};
std
::
string
KeyValue
[
3
]
=
{
"
\"
double
\"
: double
\n
"
,
"'single': single
\n
"
,
"plain: plain
\n
"
};
...
...
yaml-reader/tests.cpp
View file @
873ad336
...
@@ -262,6 +262,8 @@ namespace Test
...
@@ -262,6 +262,8 @@ namespace Test
RunParserTest
(
&
Parser
::
SimpleMap
,
"simple map"
,
passed
);
RunParserTest
(
&
Parser
::
SimpleMap
,
"simple map"
,
passed
);
RunParserTest
(
&
Parser
::
FlowSeq
,
"flow seq"
,
passed
);
RunParserTest
(
&
Parser
::
FlowSeq
,
"flow seq"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMap
,
"flow map"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMap
,
"flow map"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithOmittedKey
,
"flow map with omitted key"
,
passed
);
RunParserTest
(
&
Parser
::
FlowMapWithOmittedValue
,
"flow map with omitted value"
,
passed
);
RunParserTest
(
&
Parser
::
QuotedSimpleKeys
,
"quoted simple keys"
,
passed
);
RunParserTest
(
&
Parser
::
QuotedSimpleKeys
,
"quoted simple keys"
,
passed
);
RunParserTest
(
&
Parser
::
CompressedMapAndSeq
,
"compressed map and seq"
,
passed
);
RunParserTest
(
&
Parser
::
CompressedMapAndSeq
,
"compressed map and seq"
,
passed
);
RunParserTest
(
&
Parser
::
NullBlockSeqEntry
,
"null block seq entry"
,
passed
);
RunParserTest
(
&
Parser
::
NullBlockSeqEntry
,
"null block seq entry"
,
passed
);
...
...
yaml-reader/tests.h
View file @
873ad336
...
@@ -33,6 +33,8 @@ namespace Test {
...
@@ -33,6 +33,8 @@ namespace Test {
bool
SimpleMap
();
bool
SimpleMap
();
bool
FlowSeq
();
bool
FlowSeq
();
bool
FlowMap
();
bool
FlowMap
();
bool
FlowMapWithOmittedKey
();
bool
FlowMapWithOmittedValue
();
bool
QuotedSimpleKeys
();
bool
QuotedSimpleKeys
();
bool
CompressedMapAndSeq
();
bool
CompressedMapAndSeq
();
bool
NullBlockSeqEntry
();
bool
NullBlockSeqEntry
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment