From 002e2edc7fee5297b1bc8e1da4932d38e270f8f8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 28 Feb 2023 19:39:35 -0500 Subject: Fix incorrect parsing of strange quote escape patterns --- .reuse/dep5 | 2 +- NEWS | 3 +- src/n3.c | 12 ++++++-- test/good/manifest.ttl | 7 +++++ test/good/test-quote-escapes.nt | 52 ++++++++++++++++++++++++++++++++ test/good/test-quote-escapes.ttl | 65 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 test/good/test-quote-escapes.nt create mode 100644 test/good/test-quote-escapes.ttl 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 +Copyright: 2011-2023 David Robillard 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 Tue, 07 Feb 2023 23:34:12 +0000 + -- David Robillard 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 ; mf:result . +<#test-quote-escapes> + rdf:type rdft:TestTurtleEval ; + mf:name "test-quote-escapes" ; + mf:action ; + mf:result . + <#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 @@ + "\"" . + "\"\"" . + "\"\"\"" . + "\"\"\"\"" . + "\"" . + "\"\"" . + "\"\"" . + "\"\"\"" . + "\"\"\"" . + "\"\"\"" . + "\"\"\"" . + "\"\"\"" . + "\"\"\"\"" . + "\"\"\"\"" . + "\"\"\"\"" . + "\"\"\"\"" . + "\"\"\"\"" . + "\"\"\"\"" . + "\"\"\"\"" . + "single \" within" . + "single \" within" . + "double \"\" within" . + "double \"\" within" . + "double \"\" within" . + "double \"\" within" . + "triple \"\"\" within" . + "triple \"\"\" within" . + "triple \"\"\" within" . + "triple \"\"\" within" . + "triple \"\"\" within" . + "triple \"\"\" within" . + "triple \"\"\" within" . + "\" start single" . + "\" start single" . + "\"\" start double" . + "\"\" start double" . + "\"\" start double" . + "\"\" start double" . + "\"\"\" start triple" . + "\"\"\" start triple" . + "\"\"\" start triple" . + "\"\"\" start triple" . + "\"\"\" start triple" . + "\"\"\" start triple" . + "\"\"\" start triple" . + "end single \"" . + "end double \"\"" . + "end double \"\"" . + "end triple \"\"\"" . + "end triple \"\"\"" . + "end triple \"\"\"" . + "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 @@ + "\"" . + "\"\"" . + "\"\"\"" . + "\"\"\"\"" . + + """\"""" . + + """"\"""" . + """\"\"""" . + + """""\"""" . + """\""\"""" . + """\""\"""" . + """\"\"\"""" . + """"\"\"""" . + + """""\"\"""" . + """"\""\"""" . + """"\"\"\"""" . + """\"""\"""" . + """\""\"\"""" . + """\"\""\"""" . + """\"\"\"\"""" . + + """single " within""" . + """single \" within""" . + + """double "" within""" . + """double "\" within""" . + """double \"" within""" . + """double \"\" within""" . + + """triple ""\" within""" . + """triple "\"" within""" . + """triple "\"\" within""" . + """triple \""" within""" . + """triple \""\" within""" . + """triple \"\"" within""" . + """triple \"\"\" within""" . + + """" start single""" . + """\" start single""" . + + """"" start double""" . + """"\" start double""" . + """\"" start double""" . + """\"\" start double""" . + + """""\" start triple""" . + """"\"" start triple""" . + """"\"\" start triple""" . + """\""" start triple""" . + """\""\" start triple""" . + """\"\"" start triple""" . + """\"\"\" start triple""" . + + """end single \"""" . + + """end double "\"""" . + """end double \"\"""" . + + """end triple ""\"""" . + """end triple "\"\"""" . + """end triple \""\"""" . + """end triple \"\"\"""" . -- cgit v1.2.1