mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Fixed bug with simple keys that are quoted scalars
This commit is contained in:
@@ -309,8 +309,8 @@ namespace YAML
|
||||
{
|
||||
std::string scalar;
|
||||
|
||||
// eat single or double quote
|
||||
char quote = INPUT.get();
|
||||
// peek at single or double quote (don't eat because we need to preserve (for the time being) the input position)
|
||||
char quote = INPUT.peek();
|
||||
bool single = (quote == '\'');
|
||||
|
||||
// setup the scanning parameters
|
||||
@@ -330,6 +330,11 @@ namespace YAML
|
||||
InsertSimpleKey();
|
||||
|
||||
int line = INPUT.line, column = INPUT.column;
|
||||
|
||||
// now eat that opening quote
|
||||
INPUT.get();
|
||||
|
||||
// and scan
|
||||
scalar = ScanScalar(INPUT, params);
|
||||
m_simpleKeyAllowed = false;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "tests.h"
|
||||
#include "yaml.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Test
|
||||
{
|
||||
@@ -218,5 +219,33 @@ namespace Test
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuotedSimpleKeys()
|
||||
{
|
||||
std::string KeyValue[3] = { "\"double\": double\n", "'single': single\n", "plain: plain\n" };
|
||||
|
||||
int perm[3] = { 0, 1, 2 };
|
||||
do {
|
||||
std::string input = KeyValue[perm[0]] + KeyValue[perm[1]] + KeyValue[perm[2]];
|
||||
|
||||
std::stringstream stream(input);
|
||||
YAML::Parser parser(stream);
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
|
||||
std::string output;
|
||||
doc["double"] >> output;
|
||||
if(output != "double")
|
||||
return false;
|
||||
doc["single"] >> output;
|
||||
if(output != "single")
|
||||
return false;
|
||||
doc["plain"] >> output;
|
||||
if(output != "plain")
|
||||
return false;
|
||||
} while(std::next_permutation(perm, perm + 3));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -262,6 +262,7 @@ namespace Test
|
||||
RunParserTest(&Parser::SimpleMap, "simple map", passed);
|
||||
RunParserTest(&Parser::FlowSeq, "flow seq", passed);
|
||||
RunParserTest(&Parser::FlowMap, "flow map", passed);
|
||||
RunParserTest(&Parser::QuotedSimpleKeys, "quoted simple keys", passed);
|
||||
|
||||
RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed);
|
||||
RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed);
|
||||
|
@@ -28,6 +28,7 @@ namespace Test {
|
||||
bool SimpleMap();
|
||||
bool FlowSeq();
|
||||
bool FlowMap();
|
||||
bool QuotedSimpleKeys();
|
||||
}
|
||||
|
||||
namespace Emitter {
|
||||
|
Reference in New Issue
Block a user