Skip to content

Commit

Permalink
feat: allow quoted selectors with reserved characters
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeming committed Nov 8, 2023
1 parent 29c5b33 commit 2546bd3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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

0 comments on commit 2546bd3

Please sign in to comment.