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
68dd9b5d
Commit
68dd9b5d
authored
Jun 09, 2012
by
Jesse Beder
Browse files
Fixed bug where the parser doesn't find the end of a map or seq flow
parent
2d815c5d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
13 deletions
+47
-13
src/scanner.cpp
src/scanner.cpp
+7
-0
src/scanner.h
src/scanner.h
+1
-0
src/singledocparser.cpp
src/singledocparser.cpp
+11
-5
test/core/parsertests.cpp
test/core/parsertests.cpp
+3
-3
util/sandbox.cpp
util/sandbox.cpp
+25
-5
No files found.
src/scanner.cpp
View file @
68dd9b5d
...
@@ -51,6 +51,13 @@ namespace YAML
...
@@ -51,6 +51,13 @@ namespace YAML
return
m_tokens
.
front
();
return
m_tokens
.
front
();
}
}
// mark
// . Returns the current mark in the stream
Mark
Scanner
::
mark
()
const
{
return
INPUT
.
mark
();
}
// EnsureTokensInQueue
// EnsureTokensInQueue
// . Scan until there's a valid token at the front of the queue,
// . Scan until there's a valid token at the front of the queue,
// or we're sure the queue is empty.
// or we're sure the queue is empty.
...
...
src/scanner.h
View file @
68dd9b5d
...
@@ -31,6 +31,7 @@ namespace YAML
...
@@ -31,6 +31,7 @@ namespace YAML
bool
empty
();
bool
empty
();
void
pop
();
void
pop
();
Token
&
peek
();
Token
&
peek
();
Mark
mark
()
const
;
private:
private:
struct
IndentMarker
{
struct
IndentMarker
{
...
...
src/singledocparser.cpp
View file @
68dd9b5d
...
@@ -48,7 +48,7 @@ namespace YAML
...
@@ -48,7 +48,7 @@ namespace YAML
{
{
// an empty node *is* a possibility
// an empty node *is* a possibility
if
(
m_scanner
.
empty
())
{
if
(
m_scanner
.
empty
())
{
eventHandler
.
OnNull
(
Mark
::
null
(),
NullAnchor
);
eventHandler
.
OnNull
(
m_scanner
.
mark
(),
NullAnchor
);
return
;
return
;
}
}
...
@@ -136,7 +136,7 @@ namespace YAML
...
@@ -136,7 +136,7 @@ namespace YAML
while
(
1
)
{
while
(
1
)
{
if
(
m_scanner
.
empty
())
if
(
m_scanner
.
empty
())
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_SEQ
);
throw
ParserException
(
m_scanner
.
mark
(),
ErrorMsg
::
END_OF_SEQ
);
Token
token
=
m_scanner
.
peek
();
Token
token
=
m_scanner
.
peek
();
if
(
token
.
type
!=
Token
::
BLOCK_ENTRY
&&
token
.
type
!=
Token
::
BLOCK_SEQ_END
)
if
(
token
.
type
!=
Token
::
BLOCK_ENTRY
&&
token
.
type
!=
Token
::
BLOCK_SEQ_END
)
...
@@ -169,7 +169,7 @@ namespace YAML
...
@@ -169,7 +169,7 @@ namespace YAML
while
(
1
)
{
while
(
1
)
{
if
(
m_scanner
.
empty
())
if
(
m_scanner
.
empty
())
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_SEQ_FLOW
);
throw
ParserException
(
m_scanner
.
mark
(),
ErrorMsg
::
END_OF_SEQ_FLOW
);
// first check for end
// first check for end
if
(
m_scanner
.
peek
().
type
==
Token
::
FLOW_SEQ_END
)
{
if
(
m_scanner
.
peek
().
type
==
Token
::
FLOW_SEQ_END
)
{
...
@@ -179,6 +179,9 @@ namespace YAML
...
@@ -179,6 +179,9 @@ namespace YAML
// then read the node
// then read the node
HandleNode
(
eventHandler
);
HandleNode
(
eventHandler
);
if
(
m_scanner
.
empty
())
throw
ParserException
(
m_scanner
.
mark
(),
ErrorMsg
::
END_OF_SEQ_FLOW
);
// now eat the separator (or could be a sequence end, which we ignore - but if it's neither, then it's a bad node)
// now eat the separator (or could be a sequence end, which we ignore - but if it's neither, then it's a bad node)
Token
&
token
=
m_scanner
.
peek
();
Token
&
token
=
m_scanner
.
peek
();
...
@@ -211,7 +214,7 @@ namespace YAML
...
@@ -211,7 +214,7 @@ namespace YAML
while
(
1
)
{
while
(
1
)
{
if
(
m_scanner
.
empty
())
if
(
m_scanner
.
empty
())
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_MAP
);
throw
ParserException
(
m_scanner
.
mark
(),
ErrorMsg
::
END_OF_MAP
);
Token
token
=
m_scanner
.
peek
();
Token
token
=
m_scanner
.
peek
();
if
(
token
.
type
!=
Token
::
KEY
&&
token
.
type
!=
Token
::
VALUE
&&
token
.
type
!=
Token
::
BLOCK_MAP_END
)
if
(
token
.
type
!=
Token
::
KEY
&&
token
.
type
!=
Token
::
VALUE
&&
token
.
type
!=
Token
::
BLOCK_MAP_END
)
...
@@ -250,7 +253,7 @@ namespace YAML
...
@@ -250,7 +253,7 @@ namespace YAML
while
(
1
)
{
while
(
1
)
{
if
(
m_scanner
.
empty
())
if
(
m_scanner
.
empty
())
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_MAP_FLOW
);
throw
ParserException
(
m_scanner
.
mark
(),
ErrorMsg
::
END_OF_MAP_FLOW
);
Token
&
token
=
m_scanner
.
peek
();
Token
&
token
=
m_scanner
.
peek
();
const
Mark
mark
=
token
.
mark
;
const
Mark
mark
=
token
.
mark
;
...
@@ -275,6 +278,9 @@ namespace YAML
...
@@ -275,6 +278,9 @@ namespace YAML
}
else
{
}
else
{
eventHandler
.
OnNull
(
mark
,
NullAnchor
);
eventHandler
.
OnNull
(
mark
,
NullAnchor
);
}
}
if
(
m_scanner
.
empty
())
throw
ParserException
(
m_scanner
.
mark
(),
ErrorMsg
::
END_OF_MAP_FLOW
);
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
Token
&
nextToken
=
m_scanner
.
peek
();
Token
&
nextToken
=
m_scanner
.
peek
();
...
...
test/core/parsertests.cpp
View file @
68dd9b5d
...
@@ -6,12 +6,12 @@
...
@@ -6,12 +6,12 @@
namespace
Test
namespace
Test
{
{
namespace
Parser
{
namespace
Parser
{
TEST
BadDocStart
()
TEST
NoEndOfMapFlow
()
{
{
try
{
try
{
HANDLE
(
"---{header: {id: 1"
);
HANDLE
(
"---{header: {id: 1"
);
}
catch
(
const
YAML
::
ParserException
&
e
)
{
}
catch
(
const
YAML
::
ParserException
&
e
)
{
YAML_ASSERT
(
true
);
YAML_ASSERT
(
e
.
msg
==
std
::
string
(
YAML
::
ErrorMsg
::
END_OF_MAP_FLOW
)
);
return
true
;
return
true
;
}
}
return
" no exception caught"
;
return
" no exception caught"
;
...
@@ -43,7 +43,7 @@ namespace Test
...
@@ -43,7 +43,7 @@ namespace Test
{
{
int
passed
=
0
;
int
passed
=
0
;
int
total
=
0
;
int
total
=
0
;
RunParserTest
(
&
Parser
::
BadDocStart
,
"Bad doc start
"
,
passed
,
total
);
RunParserTest
(
&
Parser
::
NoEndOfMapFlow
,
"No end of map flow
"
,
passed
,
total
);
std
::
cout
<<
"Parser tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
std
::
cout
<<
"Parser tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
return
passed
==
total
;
...
...
util/sandbox.cpp
View file @
68dd9b5d
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/eventhandler.h"
#include <iostream>
#include <iostream>
class
NullEventHandler
:
public
YAML
::
EventHandler
{
public:
typedef
YAML
::
Mark
Mark
;
typedef
YAML
::
anchor_t
anchor_t
;
NullEventHandler
()
{}
virtual
void
OnDocumentStart
(
const
Mark
&
)
{}
virtual
void
OnDocumentEnd
()
{}
virtual
void
OnNull
(
const
Mark
&
,
anchor_t
)
{}
virtual
void
OnAlias
(
const
Mark
&
,
anchor_t
)
{}
virtual
void
OnScalar
(
const
Mark
&
,
const
std
::
string
&
,
anchor_t
,
const
std
::
string
&
)
{}
virtual
void
OnSequenceStart
(
const
Mark
&
,
const
std
::
string
&
,
anchor_t
)
{}
virtual
void
OnSequenceEnd
()
{}
virtual
void
OnMapStart
(
const
Mark
&
,
const
std
::
string
&
,
anchor_t
)
{}
virtual
void
OnMapEnd
()
{}
};
int
main
()
int
main
()
{
{
YAML
::
Emitter
out
(
std
::
cout
);
std
::
stringstream
stream
(
"---{header: {id: 1"
);
out
<<
YAML
::
BeginSeq
;
YAML
::
Parser
parser
(
stream
)
;
out
<<
"item 1"
;
//
parser.PrintTokens(std::cout)
;
out
<<
YAML
::
BeginSeq
<<
"foo 1"
<<
"bar 2"
<<
YAML
::
EndSeq
;
NullEventHandler
handler
;
out
<<
YAML
::
EndSeq
;
parser
.
HandleNextDocument
(
handler
)
;
return
0
;
return
0
;
}
}
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