aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-03-29 06:55:05 -0400
committerDavid Robillard <d@drobilla.net>2024-03-29 08:39:49 -0400
commit9facb914c72bf4d0473b49faa797cdb5c9faf68b (patch)
treeb4fe7ec1d0c285cde99cf0a9456539fcb4d719e2
parentdc3aeed6ce84736100d713cac8f40e46d16d1289 (diff)
downloadserd-9facb914c72bf4d0473b49faa797cdb5c9faf68b.tar.gz
serd-9facb914c72bf4d0473b49faa797cdb5c9faf68b.tar.bz2
serd-9facb914c72bf4d0473b49faa797cdb5c9faf68b.zip
Fix lax NQuads parsing
-rw-r--r--src/n3.c14
-rw-r--r--test/extra/lax/manifest.ttl68
-rw-r--r--test/extra/lax/test-bad-string-out.nt1
-rw-r--r--test/extra/lax/test-bad-string.nq3
-rw-r--r--test/extra/lax/test-bad-string.nt2
-rw-r--r--test/extra/lax/test-bad-uri-nq-out.nq4
-rw-r--r--test/extra/lax/test-bad-uri-out.nt4
-rw-r--r--test/extra/lax/test-bad-uri.nq4
-rw-r--r--test/extra/lax/test-bad-uri.nt4
-rw-r--r--test/extra/lax/test-bad-uri.ttl9
-rw-r--r--test/extra/lax/test-bad-utf8-nq-out.nq3
-rw-r--r--test/extra/lax/test-bad-utf8-nt-out.nt3
-rw-r--r--test/extra/lax/test-bad-utf8-ttl-out.nt6
-rw-r--r--test/extra/lax/test-bad-utf8.nq3
-rw-r--r--test/extra/lax/test-bad-utf8.nt9
15 files changed, 107 insertions, 30 deletions
diff --git a/src/n3.c b/src/n3.c
index da3862db..6684fae8 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1783,13 +1783,17 @@ read_nquads_statement(SerdReader* const reader)
SerdStatus
read_nquadsDoc(SerdReader* const reader)
{
- SerdStatus st = SERD_SUCCESS;
-
- while (!reader->source.eof && !st) {
- st = read_nquads_statement(reader);
+ while (!reader->source.eof) {
+ const SerdStatus st = read_nquads_statement(reader);
+ if (st > SERD_FAILURE) {
+ if (reader->strict) {
+ return st;
+ }
+ serd_reader_skip_until_byte(reader, '\n');
+ }
}
- return st;
+ return SERD_SUCCESS;
}
#if defined(__clang__) && __clang_major__ >= 10
diff --git a/test/extra/lax/manifest.ttl b/test/extra/lax/manifest.ttl
index a04a74f6..b9890e14 100644
--- a/test/extra/lax/manifest.ttl
+++ b/test/extra/lax/manifest.ttl
@@ -6,32 +6,74 @@
a mf:Manifest ;
rdfs:comment "Serd lax parsing test suite" ;
mf:entries (
- <#test-bad-string>
- <#test-bad-uri>
- <#test-bad-utf8>
+ <#test-bad-string-nq>
+ <#test-bad-string-nt>
+ <#test-bad-string-ttl>
+ <#test-bad-uri-nq>
+ <#test-bad-uri-nt>
+ <#test-bad-uri-ttl>
+ <#test-bad-utf8-nq>
+ <#test-bad-utf8-nt>
+ <#test-bad-utf8-ttl>
<#test-lone-list>
) .
-<#test-bad-string>
+<#test-bad-string-nq>
+ a rdft:TestNQuadsNegativeSyntax ;
+ mf:action <test-bad-string.nq> ;
+ mf:name "test-bad-string-nq" ;
+ mf:result <test-bad-string-out.nt> .
+
+<#test-bad-string-nt>
+ a rdft:TestNTriplesNegativeSyntax ;
+ mf:action <test-bad-string.nt> ;
+ mf:name "test-bad-string-nt" ;
+ mf:result <test-bad-string-out.nt> .
+
+<#test-bad-string-ttl>
a rdft:TestTurtleNegativeSyntax ;
mf:action <test-bad-string.ttl> ;
- mf:name "test-bad-string" ;
- mf:result <test-bad-string.nt> .
+ mf:name "test-bad-string-ttl" ;
+ mf:result <test-bad-string-out.nt> .
+
+<#test-bad-uri-nq>
+ a rdft:TestNQuadsNegativeSyntax ;
+ mf:action <test-bad-uri.nq> ;
+ mf:name "test-bad-uri-nq" ;
+ mf:result <test-bad-uri-nq-out.nq> .
+
+<#test-bad-uri-nt>
+ a rdft:TestNTriplesNegativeSyntax ;
+ mf:action <test-bad-uri.nt> ;
+ mf:name "test-bad-uri-nt" ;
+ mf:result <test-bad-uri-out.nt> .
-<#test-bad-uri>
+<#test-bad-uri-ttl>
a rdft:TestTurtleNegativeSyntax ;
mf:action <test-bad-uri.ttl> ;
- mf:name "test-bad-uri" ;
- mf:result <test-bad-uri.nt> .
+ mf:name "test-bad-uri-ttl" ;
+ mf:result <test-bad-uri-out.nt> .
-<#test-bad-utf8>
+<#test-bad-utf8-nq>
+ a rdft:TestNQuadsNegativeSyntax ;
+ mf:action <test-bad-utf8.nq> ;
+ mf:name "test-bad-utf8-nq" ;
+ mf:result <test-bad-utf8-nq-out.nq> .
+
+<#test-bad-utf8-nt>
+ a rdft:TestNTriplesNegativeSyntax ;
+ mf:action <test-bad-utf8.nt> ;
+ mf:name "test-bad-utf8-nt" ;
+ mf:result <test-bad-utf8-nt-out.nt> .
+
+<#test-bad-utf8-ttl>
a rdft:TestTurtleNegativeSyntax ;
mf:action <test-bad-utf8.ttl> ;
- mf:name "test-bad-utf8" ;
- mf:result <test-bad-utf8.nt> .
+ mf:name "test-bad-utf8-ttl" ;
+ mf:result <test-bad-utf8-ttl-out.nt> .
<#test-lone-list>
a rdft:TestTurtleNegativeSyntax ;
- mf:name "test-lone-list" ;
mf:action <test-lone-list.ttl> ;
+ mf:name "test-lone-list" ;
mf:result <test-lone-list.nt> .
diff --git a/test/extra/lax/test-bad-string-out.nt b/test/extra/lax/test-bad-string-out.nt
new file mode 100644
index 00000000..24f80a2e
--- /dev/null
+++ b/test/extra/lax/test-bad-string-out.nt
@@ -0,0 +1 @@
+<http://example.org/s1> <http://example.org/p2> "Good" .
diff --git a/test/extra/lax/test-bad-string.nq b/test/extra/lax/test-bad-string.nq
new file mode 100644
index 00000000..72eb9621
--- /dev/null
+++ b/test/extra/lax/test-bad-string.nq
@@ -0,0 +1,3 @@
+<http://example.org/s1> <http://example.org/p1> "Truncated line
+<http://example.org/s1> <http://example.org/p1> "Bad escape \? " .
+<http://example.org/s1> <http://example.org/p2> "Good" .
diff --git a/test/extra/lax/test-bad-string.nt b/test/extra/lax/test-bad-string.nt
index 24f80a2e..72eb9621 100644
--- a/test/extra/lax/test-bad-string.nt
+++ b/test/extra/lax/test-bad-string.nt
@@ -1 +1,3 @@
+<http://example.org/s1> <http://example.org/p1> "Truncated line
+<http://example.org/s1> <http://example.org/p1> "Bad escape \? " .
<http://example.org/s1> <http://example.org/p2> "Good" .
diff --git a/test/extra/lax/test-bad-uri-nq-out.nq b/test/extra/lax/test-bad-uri-nq-out.nq
new file mode 100644
index 00000000..e14f3a08
--- /dev/null
+++ b/test/extra/lax/test-bad-uri-nq-out.nq
@@ -0,0 +1,4 @@
+<http://example.org/s> <http://example.org/p> <http://example.org/\u0009bado1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/goodo1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/�bado2> .
+<http://example.org/s> <http://example.org/p> <http://example.org/goodo2> .
diff --git a/test/extra/lax/test-bad-uri-out.nt b/test/extra/lax/test-bad-uri-out.nt
new file mode 100644
index 00000000..8cb00ba7
--- /dev/null
+++ b/test/extra/lax/test-bad-uri-out.nt
@@ -0,0 +1,4 @@
+<http://example.org/s> <http://example.org/p> <http://example.org/\u0009bado1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/goodo1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/\uFFFDbado2> .
+<http://example.org/s> <http://example.org/p> <http://example.org/goodo2> .
diff --git a/test/extra/lax/test-bad-uri.nq b/test/extra/lax/test-bad-uri.nq
new file mode 100644
index 00000000..8f11b1d7
--- /dev/null
+++ b/test/extra/lax/test-bad-uri.nq
@@ -0,0 +1,4 @@
+<http://example.org/s> <http://example.org/p> <http://example.org/ bado1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/goodo1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/ÿÿbado2> .
+<http://example.org/s> <http://example.org/p> <http://example.org/goodo2> .
diff --git a/test/extra/lax/test-bad-uri.nt b/test/extra/lax/test-bad-uri.nt
index 8cb00ba7..8f11b1d7 100644
--- a/test/extra/lax/test-bad-uri.nt
+++ b/test/extra/lax/test-bad-uri.nt
@@ -1,4 +1,4 @@
-<http://example.org/s> <http://example.org/p> <http://example.org/\u0009bado1> .
+<http://example.org/s> <http://example.org/p> <http://example.org/ bado1> .
<http://example.org/s> <http://example.org/p> <http://example.org/goodo1> .
-<http://example.org/s> <http://example.org/p> <http://example.org/\uFFFDbado2> .
+<http://example.org/s> <http://example.org/p> <http://example.org/ÿÿbado2> .
<http://example.org/s> <http://example.org/p> <http://example.org/goodo2> .
diff --git a/test/extra/lax/test-bad-uri.ttl b/test/extra/lax/test-bad-uri.ttl
index 8f11b1d7..1a724fd1 100644
--- a/test/extra/lax/test-bad-uri.ttl
+++ b/test/extra/lax/test-bad-uri.ttl
@@ -1,4 +1,5 @@
-<http://example.org/s> <http://example.org/p> <http://example.org/ bado1> .
-<http://example.org/s> <http://example.org/p> <http://example.org/goodo1> .
-<http://example.org/s> <http://example.org/p> <http://example.org/ÿÿbado2> .
-<http://example.org/s> <http://example.org/p> <http://example.org/goodo2> .
+<http://example.org/s>
+ <http://example.org/p> <http://example.org/ bado1> ,
+ <http://example.org/goodo1> ;
+ <http://example.org/p> <http://example.org/ÿÿbado2> ;
+ <http://example.org/p> <http://example.org/goodo2> .
diff --git a/test/extra/lax/test-bad-utf8-nq-out.nq b/test/extra/lax/test-bad-utf8-nq-out.nq
new file mode 100644
index 00000000..554cf199
--- /dev/null
+++ b/test/extra/lax/test-bad-utf8-nq-out.nq
@@ -0,0 +1,3 @@
+<http://example.org/s> <http://example.org/p> "Impossible bytes: � �" .
+<http://example.org/s> <http://example.org/p> "2 continuation bytes: �" .
+<http://example.org/s> <http://example.org/p> "Missing continuation: �" .
diff --git a/test/extra/lax/test-bad-utf8-nt-out.nt b/test/extra/lax/test-bad-utf8-nt-out.nt
new file mode 100644
index 00000000..8cefa258
--- /dev/null
+++ b/test/extra/lax/test-bad-utf8-nt-out.nt
@@ -0,0 +1,3 @@
+<http://example.org/s> <http://example.org/p> "Impossible bytes: \uFFFD \uFFFD" .
+<http://example.org/s> <http://example.org/p> "2 continuation bytes: \uFFFD" .
+<http://example.org/s> <http://example.org/p> "Missing continuation: \uFFFD" .
diff --git a/test/extra/lax/test-bad-utf8-ttl-out.nt b/test/extra/lax/test-bad-utf8-ttl-out.nt
new file mode 100644
index 00000000..58f2c52b
--- /dev/null
+++ b/test/extra/lax/test-bad-utf8-ttl-out.nt
@@ -0,0 +1,6 @@
+<http://example.org/s> <http://example.org/p> "Impossible bytes: \uFFFD \uFFFD" .
+<http://example.org/s> <http://example.org/p> "2 continuation bytes: \uFFFD" .
+<http://example.org/s> <http://example.org/p> "Missing continuation: \uFFFD" .
+<http://example.org/s> <http://example.org/p> "Impossible bytes: \uFFFD \uFFFD" .
+<http://example.org/s> <http://example.org/p> "2 continuation bytes: \uFFFD" .
+<http://example.org/s> <http://example.org/p> "Missing continuation: \uFFFD" .
diff --git a/test/extra/lax/test-bad-utf8.nq b/test/extra/lax/test-bad-utf8.nq
new file mode 100644
index 00000000..b8c04637
--- /dev/null
+++ b/test/extra/lax/test-bad-utf8.nq
@@ -0,0 +1,3 @@
+<http://example.org/s> <http://example.org/p> "Impossible bytes: þ ÿ" .
+<http://example.org/s> <http://example.org/p> "2 continuation bytes: €¿" .
+<http://example.org/s> <http://example.org/p> "Missing continuation: À" .
diff --git a/test/extra/lax/test-bad-utf8.nt b/test/extra/lax/test-bad-utf8.nt
index 58f2c52b..b8c04637 100644
--- a/test/extra/lax/test-bad-utf8.nt
+++ b/test/extra/lax/test-bad-utf8.nt
@@ -1,6 +1,3 @@
-<http://example.org/s> <http://example.org/p> "Impossible bytes: \uFFFD \uFFFD" .
-<http://example.org/s> <http://example.org/p> "2 continuation bytes: \uFFFD" .
-<http://example.org/s> <http://example.org/p> "Missing continuation: \uFFFD" .
-<http://example.org/s> <http://example.org/p> "Impossible bytes: \uFFFD \uFFFD" .
-<http://example.org/s> <http://example.org/p> "2 continuation bytes: \uFFFD" .
-<http://example.org/s> <http://example.org/p> "Missing continuation: \uFFFD" .
+<http://example.org/s> <http://example.org/p> "Impossible bytes: þ ÿ" .
+<http://example.org/s> <http://example.org/p> "2 continuation bytes: €¿" .
+<http://example.org/s> <http://example.org/p> "Missing continuation: À" .