Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for quoted selectors containing reserved characters and white space #3

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ It can be any non empty Unicode string that doesn’t contain reserved character
The specific syntax of the selector is not enforced by this parser.

----
selector = unreserved-str;
selector = unreserved-str | double-quoted | single-quoted;
----

Comparison operators are in FIQL notation and some of them has an alternative syntax as well:
Expand Down
6 changes: 4 additions & 2 deletions src/main/javacc/RSQLParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ ComparisonNode Comparison():

String Selector(): {}
{
token = <UNRESERVED_STR>
token = <UNRESERVED_STR> { return token.image; }
|
( token = <DOUBLE_QUOTED_STR> | token = <SINGLE_QUOTED_STR> )
{
return token.image;
return unescape(token.image);
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/test/groovy/cz/jirutka/rsql/parser/RSQLParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ class RSQLParserTest extends Specification {
'allons-y', 'l00k.dot.path', 'look/XML/path', 'n:look/n:xml', 'path.to::Ref', '$doll_r.way' ]
}

def 'throw exception for selector with reserved char: #input'() {
def 'parse quoted selector with any chars: #input'() {
given:
def expected = eq(input[1..-2], 'val')
expect:
parse("${input}==val") == expected
where:
input << [ '"hi there!"', "'Pěkný den!'", '"Flynn\'s *"', '"o)\'O\'(o"', '"6*7=42"' ]
}

def 'throw exception for selector with unquoted reserved char: #input'() {
when:
parse("${input}==val")
then:
Expand Down