Repository navigation
Conversation
The parser only matched a single space on each side of these operator names, so a tab or a line break between the tokens, which XPath 1.0 allows, raised ParseException.
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The XPath parser only recognised the operator names
and,or,divandmodwhen they were surrounded by one literal space, because the patterns were/\A\s*( or )/,/\A\s*( and )/and/\A\s*(\*| div | mod )\s*/. The grammar comments right above them sayS 'or' S, and XPath 1.0 allows any whitespace there (Sis a space, tab, CR or LF). So a tab or a line break between the tokens raisedParseException, which is the same family of problem as #397 (line breaks inside expressions) and #393 (spaces).Real results of
REXML::Parsers::XPathParser.new.parse(...)onmasterwithaandbas operands:a and b[:and, [...a], [...b]]a\tand\tbParseException("Garbage component exists at the end")a and ba\nor\nbParseExceptiona or ba\ndiv\nb,a\tmod\tbParseExceptionTo find every affected case I compared the parse tree of the same expression written with different spacing: 10 operand pairs (names, numbers, attributes, paths, function calls, strings, variables, parentheses, predicates,
.and..) × 14 operators × several spacings, 824 comparisons. Before the change 80 of them differed: 72 are exactly this problem (4 word operators × tab or newline × 9 operand pairs). The other 8 (a-b,a- b,$v-1, ...) are correct, because a hyphen belongs to a name in XPath, so I left them alone. After the change only those 8 differ.The fix replaces the single-space patterns with "one or more whitespace characters" around the names (
/\A\s+(or)\s+/,/\A\s+(and)\s+/and/\A\s*(\*|\s(?:div|mod)\s)\s*/). Everything that parsed before still parses to the same tree: the new patterns accept a superset of the old ones, and I did not change the symbol operators.Test:
test_word_operators_with_any_whitespaceintest/parser/test_xpath.rb(the four operators with a tab, LF, CRLF and a mixed separator, plus the same inside a predicate and adiv/modchain). It fails onmaster(REXML::ParseException: Garbage component exists at the end: <\tand\tb>) and passes now.rake testpasses (879 tests, 0 failures, 5 omissions as before). I did not run a linter, since I did not find one configured for this repo.