aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-02-28 19:39:35 -0500
committerDavid Robillard <d@drobilla.net>2023-03-31 11:10:52 -0400
commit002e2edc7fee5297b1bc8e1da4932d38e270f8f8 (patch)
treee701cf2bcf6663f3b7dd79234b6f3145e4e46f26
parent647179b76fe15e5306a5a4f7ebbc1ad933d5a526 (diff)
downloadserd-002e2edc7fee5297b1bc8e1da4932d38e270f8f8.tar.gz
serd-002e2edc7fee5297b1bc8e1da4932d38e270f8f8.tar.bz2
serd-002e2edc7fee5297b1bc8e1da4932d38e270f8f8.zip
Fix incorrect parsing of strange quote escape patterns
-rw-r--r--.reuse/dep52
-rw-r--r--NEWS3
-rw-r--r--src/n3.c12
-rw-r--r--test/good/manifest.ttl7
-rw-r--r--test/good/test-quote-escapes.nt52
-rw-r--r--test/good/test-quote-escapes.ttl65
6 files changed, 136 insertions, 5 deletions
diff --git a/.reuse/dep5 b/.reuse/dep5
index 53511c48..d7d4151f 100644
--- a/.reuse/dep5
+++ b/.reuse/dep5
@@ -14,7 +14,7 @@ Comment: Extra tests for serd (potential contributions to the W3C suites)
License: BSD-3-Clause OR ISC
Files: AUTHORS NEWS serd.ttl
-Copyright: 2011-2022 David Robillard <d@drobilla.net>
+Copyright: 2011-2023 David Robillard <d@drobilla.net>
Comment: Contributed to the Commons as a representation of simple facts
License: 0BSD OR ISC
diff --git a/NEWS b/NEWS
index b9a34beb..4d8fd5fa 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ serd (0.31.0) unstable; urgency=medium
* Clean up code
* Fix crash when trying to read chunks without starting
* Fix hang when skipping an error at EOF when lax parsing
+ * Fix incorrect parsing of strange quote escape patterns
* Gracefully handle bad characters in Turtle blank node syntax
* Gracefully handle bad characters in Turtle datatype syntax
* Improve serdi man page
@@ -16,7 +17,7 @@ serd (0.31.0) unstable; urgency=medium
* Replace duplicated dox_to_sphinx script with sphinxygen dependency
* Test header for warnings more strictly
- -- David Robillard <d@drobilla.net> Tue, 07 Feb 2023 23:34:12 +0000
+ -- David Robillard <d@drobilla.net> Wed, 01 Mar 2023 00:36:43 +0000
serd (0.30.16) stable; urgency=medium
diff --git a/src/n3.c b/src/n3.c
index 71a2fc56..e14cb8ce 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -361,9 +361,15 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
skip_byte(reader, q3);
break;
}
- *flags |= SERD_HAS_QUOTE;
- push_byte(reader, ref, c);
- st = read_character(reader, ref, flags, (uint8_t)q2);
+
+ if (q2 == '\\') {
+ push_byte(reader, ref, c);
+ st = read_string_escape(reader, ref, flags);
+ } else {
+ *flags |= SERD_HAS_QUOTE;
+ push_byte(reader, ref, c);
+ st = read_character(reader, ref, flags, (uint8_t)q2);
+ }
} else if (c == EOF) {
return r_err(reader, SERD_ERR_BAD_SYNTAX, "end of file in long string\n");
} else {
diff --git a/test/good/manifest.ttl b/test/good/manifest.ttl
index 00009c4f..25359fdc 100644
--- a/test/good/manifest.ttl
+++ b/test/good/manifest.ttl
@@ -45,6 +45,7 @@
<#test-out-of-range-unicode>
<#test-prefix>
<#test-pretty>
+ <#test-quote-escapes>
<#test-rel>
<#test-semi-dot>
<#test-uri-escape>
@@ -281,6 +282,12 @@
mf:action <test-pretty.ttl> ;
mf:result <test-pretty.nt> .
+<#test-quote-escapes>
+ rdf:type rdft:TestTurtleEval ;
+ mf:name "test-quote-escapes" ;
+ mf:action <test-quote-escapes.ttl> ;
+ mf:result <test-quote-escapes.nt> .
+
<#test-rel>
rdf:type rdft:TestTurtleEval ;
mf:name "test-rel" ;
diff --git a/test/good/test-quote-escapes.nt b/test/good/test-quote-escapes.nt
new file mode 100644
index 00000000..26c06a8d
--- /dev/null
+++ b/test/good/test-quote-escapes.nt
@@ -0,0 +1,52 @@
+<http://example.org/s> <http://example.org/p> "\"" .
+<http://example.org/s> <http://example.org/p> "\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"" .
+<http://example.org/s> <http://example.org/p> "\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+<http://example.org/s> <http://example.org/p> "single \" within" .
+<http://example.org/s> <http://example.org/p> "single \" within" .
+<http://example.org/s> <http://example.org/p> "double \"\" within" .
+<http://example.org/s> <http://example.org/p> "double \"\" within" .
+<http://example.org/s> <http://example.org/p> "double \"\" within" .
+<http://example.org/s> <http://example.org/p> "double \"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "triple \"\"\" within" .
+<http://example.org/s> <http://example.org/p> "\" start single" .
+<http://example.org/s> <http://example.org/p> "\" start single" .
+<http://example.org/s> <http://example.org/p> "\"\" start double" .
+<http://example.org/s> <http://example.org/p> "\"\" start double" .
+<http://example.org/s> <http://example.org/p> "\"\" start double" .
+<http://example.org/s> <http://example.org/p> "\"\" start double" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "\"\"\" start triple" .
+<http://example.org/s> <http://example.org/p> "end single \"" .
+<http://example.org/s> <http://example.org/p> "end double \"\"" .
+<http://example.org/s> <http://example.org/p> "end double \"\"" .
+<http://example.org/s> <http://example.org/p> "end triple \"\"\"" .
+<http://example.org/s> <http://example.org/p> "end triple \"\"\"" .
+<http://example.org/s> <http://example.org/p> "end triple \"\"\"" .
+<http://example.org/s> <http://example.org/p> "end triple \"\"\"" .
diff --git a/test/good/test-quote-escapes.ttl b/test/good/test-quote-escapes.ttl
new file mode 100644
index 00000000..ffe14807
--- /dev/null
+++ b/test/good/test-quote-escapes.ttl
@@ -0,0 +1,65 @@
+<http://example.org/s> <http://example.org/p> "\"" .
+<http://example.org/s> <http://example.org/p> "\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"" .
+<http://example.org/s> <http://example.org/p> "\"\"\"\"" .
+
+<http://example.org/s> <http://example.org/p> """\"""" .
+
+<http://example.org/s> <http://example.org/p> """"\"""" .
+<http://example.org/s> <http://example.org/p> """\"\"""" .
+
+<http://example.org/s> <http://example.org/p> """""\"""" .
+<http://example.org/s> <http://example.org/p> """\""\"""" .
+<http://example.org/s> <http://example.org/p> """\""\"""" .
+<http://example.org/s> <http://example.org/p> """\"\"\"""" .
+<http://example.org/s> <http://example.org/p> """"\"\"""" .
+
+<http://example.org/s> <http://example.org/p> """""\"\"""" .
+<http://example.org/s> <http://example.org/p> """"\""\"""" .
+<http://example.org/s> <http://example.org/p> """"\"\"\"""" .
+<http://example.org/s> <http://example.org/p> """\"""\"""" .
+<http://example.org/s> <http://example.org/p> """\""\"\"""" .
+<http://example.org/s> <http://example.org/p> """\"\""\"""" .
+<http://example.org/s> <http://example.org/p> """\"\"\"\"""" .
+
+<http://example.org/s> <http://example.org/p> """single " within""" .
+<http://example.org/s> <http://example.org/p> """single \" within""" .
+
+<http://example.org/s> <http://example.org/p> """double "" within""" .
+<http://example.org/s> <http://example.org/p> """double "\" within""" .
+<http://example.org/s> <http://example.org/p> """double \"" within""" .
+<http://example.org/s> <http://example.org/p> """double \"\" within""" .
+
+<http://example.org/s> <http://example.org/p> """triple ""\" within""" .
+<http://example.org/s> <http://example.org/p> """triple "\"" within""" .
+<http://example.org/s> <http://example.org/p> """triple "\"\" within""" .
+<http://example.org/s> <http://example.org/p> """triple \""" within""" .
+<http://example.org/s> <http://example.org/p> """triple \""\" within""" .
+<http://example.org/s> <http://example.org/p> """triple \"\"" within""" .
+<http://example.org/s> <http://example.org/p> """triple \"\"\" within""" .
+
+<http://example.org/s> <http://example.org/p> """" start single""" .
+<http://example.org/s> <http://example.org/p> """\" start single""" .
+
+<http://example.org/s> <http://example.org/p> """"" start double""" .
+<http://example.org/s> <http://example.org/p> """"\" start double""" .
+<http://example.org/s> <http://example.org/p> """\"" start double""" .
+<http://example.org/s> <http://example.org/p> """\"\" start double""" .
+
+<http://example.org/s> <http://example.org/p> """""\" start triple""" .
+<http://example.org/s> <http://example.org/p> """"\"" start triple""" .
+<http://example.org/s> <http://example.org/p> """"\"\" start triple""" .
+<http://example.org/s> <http://example.org/p> """\""" start triple""" .
+<http://example.org/s> <http://example.org/p> """\""\" start triple""" .
+<http://example.org/s> <http://example.org/p> """\"\"" start triple""" .
+<http://example.org/s> <http://example.org/p> """\"\"\" start triple""" .
+
+<http://example.org/s> <http://example.org/p> """end single \"""" .
+
+<http://example.org/s> <http://example.org/p> """end double "\"""" .
+<http://example.org/s> <http://example.org/p> """end double \"\"""" .
+
+<http://example.org/s> <http://example.org/p> """end triple ""\"""" .
+<http://example.org/s> <http://example.org/p> """end triple "\"\"""" .
+<http://example.org/s> <http://example.org/p> """end triple \""\"""" .
+<http://example.org/s> <http://example.org/p> """end triple \"\"\"""" .