Skip to content

Commit

Permalink
Fixed two small Bugs
Browse files Browse the repository at this point in the history
- The previous escaping fix had the internal SparqlParser::parseLiteral function called after parsing the literal inside
  the Lexer. This is unwanted and led to strange behavior. This is just a small fix for a much bigger issue:
  All kinds of different types of Triple and Query elements are encoded als std::string, this makes it very easy to mix things up and create bugs.

- The prefix filter now for ages has retrieved one element too much.
  • Loading branch information
joka921 committed Jan 11, 2020
1 parent d49bed7 commit b82e5dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/engine/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void Filter::computeFilterFixedValue(
// within the range.
rhs_array[lhs] = upperBound;
const auto& upper =
std::upper_bound(lower, input.end(), rhs_row,
std::lower_bound(lower, input.end(), rhs_row,
[lhs](const auto& l, const auto& r) {
return l[lhs] < r[lhs];
});
Expand Down
26 changes: 18 additions & 8 deletions src/parser/SparqlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "./ParseException.h"
#include "PropertyPathParser.h"

using namespace std::literals::string_literals;

SparqlParser::SparqlParser(const string& query) : _lexer(query), _query(query) {
LOG(DEBUG) << "Parsing " << query << std::endl;
}
Expand Down Expand Up @@ -691,7 +693,7 @@ bool SparqlParser::parseFilter(
f._rhs = _lexer.current().raw;
} else if (_lexer.accept(SparqlToken::Type::RDFLITERAL)) {
// Resolve escaped characters
f._rhs = parseLiteral(_lexer.current().raw, true);
f._rhs = _lexer.current().raw;
} else if (_lexer.accept(SparqlToken::Type::INTEGER)) {
f._rhs = _lexer.current().raw;
} else if (_lexer.accept(SparqlToken::Type::FLOAT)) {
Expand All @@ -713,7 +715,7 @@ bool SparqlParser::parseFilter(
_lexer.expect(")");
_lexer.expect(",");
_lexer.expect(SparqlToken::Type::RDFLITERAL);
std::string rhs = parseLiteral(_lexer.current().raw, true);
std::string rhs = _lexer.current().raw;
_lexer.expect(")");
addLangFilter(lhs, rhs, pattern);
return true;
Expand All @@ -732,7 +734,7 @@ bool SparqlParser::parseFilter(
}
_lexer.expect(",");
_lexer.expect(SparqlToken::Type::RDFLITERAL);
f._rhs = parseLiteral(_lexer.current().raw, true);
f._rhs = _lexer.current().raw;
// Remove the enlcosing quotation marks
f._rhs = f._rhs.substr(1, f._rhs.size() - 2);
if (_lexer.accept(",")) {
Expand Down Expand Up @@ -761,11 +763,19 @@ bool SparqlParser::parseFilter(
escaped = !escaped; // correctly deal with consecutive backslashes
continue;
}
if (!escaped) {
char c = f._rhs[i];
if (regexControlChars.find(c) != string::npos) {
isSimple = false;
}
char c = f._rhs[i];
bool isControlChar = regexControlChars.find(c) != string::npos;
if (!escaped && isControlChar) {
isSimple = false;
} else if (escaped && !isControlChar) {
const std::string error =
"Escaping the character "s + c +
" is not allowed in QLever's regex filters. (Regex was " +
f._rhs +
") Please note that "
"there are two levels of Escaping in place here: One for Sparql "
"and one for the regex engine";
throw ParseException(error);
}
escaped = false;
}
Expand Down

0 comments on commit b82e5dd

Please sign in to comment.