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

Add syntax tests for codepoint escaping. #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions sparql/sparql12/manifest.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trs:manifest rdf:type mf:Manifest ;
""";
mf:include (
<grouping/manifest.ttl>
<syntax-escaping/manifest.ttl>
<syntax-triple-terms-negative/manifest.ttl>
<syntax-triple-terms-positive/manifest.ttl>
) .
7 changes: 7 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-01.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT * WHERE {
?s ?p "\\u000Z"
}

# \u000Z is an invalid escape sequence. It should either: be left as-is
# as it does not match the escape syntax of `\u HEX HEX HEX HEX`; or
# seen as a syntax error.
8 changes: 8 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-02.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PREFIX ns: <http://example.org/>
SELECT * WHERE {
?s ?p ns:id\u005c=123
}

# the escape here produces '\' REVERSE SOLIDUS (U+5C)
# its unescaping must lead to a Prefixed Name ns:id\=123 using an escaped
# equals sign (U+3D), representing the IRI <http://example.org/id=123>.
5 changes: 5 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-03.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT * WHERE {
?s ?p "\\u0041"
}
# Legal codepoint escape of LATIN CAPITAL LETTER A (U+41), resulting in an
# invalid backslash escape \A.
5 changes: 5 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-04.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT * WHERE {
?s ?p "\\u0074"
}
# Legal codepoint escape of LATIN SMALL LETTER T (U+74), resulting in a
# valid backslash escape \t for CHARACTER TABULATION (U+9).
5 changes: 5 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-05.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT * WHERE {
?s ?p "\u005C\u005Cn"
}
# Two legal codepoint escapes of REVERSE SOLIDUS (U+5C), resulting in a
# valid backslash escape \\ for REVERSE SOLIDUS (U+5C) followed by 'n'.
8 changes: 8 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-06.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PREFIX og: <http://ogp.me/ns#>
SELECT * WHERE {
?page og:audio\u00253Atitle ?title
}

# the escape here produces '%' PERCENT SIGN (U+25)
# its unescaping must lead to a Prefixed Name og:audio%3Atitle which includes
# the percent-encoding %3A (COLON).
7 changes: 7 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-07.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT\u0020*\U00000009WHERE {
?s ?p "value"
}

# the escapes here produce whitespace -- SPACESPACE (U+20) and
# CHARACTER TABULATION (U+9) -- surrounding the `*` token in the
# SELECT projection.
6 changes: 6 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-08.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT * WHERE {
?s ?p \u0022value"
}

# the escape here produces QUOTATION MARK (U+22)
# its unescaping must lead to the literal 'value'.
3 changes: 3 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-09.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\u0041\u0053\u004B\u0020\u007B\u007D

# The query `ASK {}` entirely encoded using codepoint escapes.
11 changes: 11 additions & 0 deletions sparql/sparql12/syntax-escaping/codepoint-esc-10.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT * WHERE {
?s ?p "\\u000\u241e"
}

# \u000\ is an invalid escape sequence, while \u241e is a valid sequence.
# The interpretation here depends on whether the entire six-character sequence `\u000\`
# is consumed during parsing/tokenizing and left as-is (or raised as an error),
# or whether the final character is recognized as the first character of a valid
# codepoint escape sequence. If the latter, the unescaping should result in a
# six-codepoint literal whose five-character prefix is "\u000", followed by
# SYMBOL FOR RECORD SEPARATOR (U+241E).
81 changes: 81 additions & 0 deletions sparql/sparql12/syntax-escaping/manifest.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <https://w3c.github.io/rdf-tests/sparql/sparql12/escaping#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
@prefix qt: <http://www.w3.org/2001/sw/DataAccess/tests/test-query#> .
@prefix dawgt: <http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#> .

:manifest rdf:type mf:Manifest ;
rdfs:label "SPARQL Codepoint-Escaping Tests" ;
mf:entries
(
:codepoint-esc-01
:codepoint-esc-02
:codepoint-esc-03
:codepoint-esc-04
:codepoint-esc-05
:codepoint-esc-06
:codepoint-esc-07
:codepoint-esc-08
:codepoint-esc-09
:codepoint-esc-10
) .


:codepoint-esc-01 rdf:type mf:PositiveSyntaxTest ; # TODO: depends on decision on handling of invalid escapes
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-01.rq" ;
rdfs:comment "invalid codepoint escape (requires handling codepoint escaping before backslash escaping)" ;
mf:action <codepoint-esc-01.rq> .

:codepoint-esc-02 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-02.rq" ;
rdfs:comment "codepoint escape for the backslash of a PN_LOCAL_ESC in the PN_LOCAL part of a PrefixedName" ;
mf:action <codepoint-esc-02.rq> .

:codepoint-esc-03 rdf:type mf:NegativeSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-03.rq" ;
rdfs:comment "codepoint escape that results in an invalid backslash escape (requires handling codepoint escaping before backslash escaping)" ;
mf:action <codepoint-esc-03.rq> .

:codepoint-esc-04 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-04.rq" ;
rdfs:comment "codepoint escape that results in a valid backslash escape" ;
mf:action <codepoint-esc-04.rq> .

:codepoint-esc-05 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-05.rq" ;
mf:action <codepoint-esc-05.rq> .

:codepoint-esc-06 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-06.rq" ;
rdfs:comment "codepoint escape for the percent sign in the PL_LOCAL part of a PrefixedName" ;
mf:action <codepoint-esc-06.rq> .

:codepoint-esc-07 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-07.rq" ;
rdfs:comment "codepoint escape for whitespace separating the projection tokens: SELECT * WHERE" ;
mf:action <codepoint-esc-07.rq> .

:codepoint-esc-08 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-08.rq" ;
rdfs:comment "codepoint escape for the starting double-quote of a literal" ;
mf:action <codepoint-esc-08.rq> .

:codepoint-esc-09 rdf:type mf:PositiveSyntaxTest ;
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-09.rq" ;
mf:action <codepoint-esc-09.rq> .

:codepoint-esc-10 rdf:type mf:PositiveSyntaxTest ; # TODO: depends on decision on handling of invalid escapes
dawgt:approval dawgt:Proposed ;
mf:name "codepoint-esc-10.rq" ;
rdfs:comment "overlapping codepoint escapes" ;
mf:action <codepoint-esc-10.rq> .
Loading