Skip to content

Commit

Permalink
Fixed a parsing error when triple part parsing ended on }
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankramer committed Jun 27, 2019
1 parent 11c5897 commit 49b8c1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/parser/SparqlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ std::string_view SparqlParser::readTriplePart(const std::string& s,
insidePrefixed = true;
}
} else if (insidePrefixed) {
if (std::isspace(static_cast<unsigned char>(s[*pos]))) {
if (std::isspace(static_cast<unsigned char>(s[*pos])) || s[*pos] == '}') {
return std::string_view(s.data() + start, (*pos) - start);
} else if (s[*pos] == '.' || s[*pos] == ';' || s[*pos] == ',') {
if ((*pos) + 1 >= s.size() ||
Expand Down
12 changes: 3 additions & 9 deletions test/SparqlParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ SELECT ?a ?b ?c WHERE {
{"<Freiherr>", "<Lord_of_the_Isles>"}};
ASSERT_EQ(vvals, values2._values);

pq = SparqlParser::parse(""
pq = SparqlParser::parse(
""
"PREFIX wd: <http://www.wikidata.org/entity/>\n"
"PREFIX wdt: <http://www.wikidata.org/prop/direct/>\n"
"SELECT ?city WHERE {\n"
Expand All @@ -278,20 +279,13 @@ SELECT ?a ?b ?c WHERE {

ASSERT_EQ(pq._rootGraphPattern->_whereClauseTriples[0]._s, "?city");
ASSERT_EQ(pq._rootGraphPattern->_whereClauseTriples[0]._p._iri, "wdt:P31");
ASSERT_EQ(pq._rootGraphPattern->_whereClauseTriples[0]._s, "?citytype");
ASSERT_EQ(pq._rootGraphPattern->_whereClauseTriples[0]._s, "?city");

values1 = pq._rootGraphPattern->_inlineValues[0];
vvars = {"?citytype"};
ASSERT_EQ(vvars, values1._variables);
vvals = {{"wd:Q515"}, {"wd:Q262166"}};
ASSERT_EQ(vvals, values1._values);

values2 = pq._rootGraphPattern->_inlineValues[1];
vvars = {"?b", "?c"};
ASSERT_EQ(vvars, values2._variables);
vvals = {{"<Marie_Curie>", "<Joseph_Jacobson>"},
{"<Freiherr>", "<Lord_of_the_Isles>"}};
ASSERT_EQ(vvals, values2._values);
} catch (const ad_semsearch::Exception& e) {
FAIL() << e.getFullErrorMessage();
}
Expand Down

0 comments on commit 49b8c1e

Please sign in to comment.