aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-04-09 15:41:36 -0400
committerDavid Robillard <d@drobilla.net>2021-04-09 16:15:00 -0400
commita627bf523eba114b0e2466c77bd379d17c7195c6 (patch)
treec0951958a93da739005ffab2ab5b216cb5eef8ec
parent36f1cecc1fdb803bf04d2ab60bd13dd257a9e525 (diff)
downloadserd-a627bf523eba114b0e2466c77bd379d17c7195c6.tar.gz
serd-a627bf523eba114b0e2466c77bd379d17c7195c6.tar.bz2
serd-a627bf523eba114b0e2466c77bd379d17c7195c6.zip
Write statements with invalid URI characters in lax mode
-rw-r--r--NEWS3
-rw-r--r--src/n3.c18
-rw-r--r--test/lax/manifest.ttl7
-rw-r--r--test/lax/test-bad-string.nt1
-rw-r--r--test/lax/test-bad-string.ttl3
-rw-r--r--test/lax/test-bad-uri.nt1
-rw-r--r--test/test_reader_writer.c1
7 files changed, 24 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 03636d41..ef15d1fb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,9 @@
serd (0.30.11) unstable;
* Fix writing long literals with triple quotes
+ * Write statements with invalid URI characters in lax mode
- -- David Robillard <d@drobilla.net> Mon, 15 Feb 2021 16:34:35 +0000
+ -- David Robillard <d@drobilla.net> Fri, 09 Apr 2021 19:40:44 +0000
serd (0.30.10) stable;
diff --git a/src/n3.c b/src/n3.c
index 9aae8a19..9e9d5327 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -723,7 +723,7 @@ read_IRIREF(SerdReader* reader, Ref* dest)
SerdStatus st = SERD_SUCCESS;
uint32_t code = 0;
- while (!st) {
+ while (st <= SERD_FAILURE) {
const int c = eat_byte_safe(reader, peek_byte(reader));
switch (c) {
case '"':
@@ -767,16 +767,16 @@ read_IRIREF(SerdReader* reader, Ref* dest)
default:
if (c <= 0x20) {
- r_err(reader,
- SERD_ERR_BAD_SYNTAX,
- "invalid IRI character (escape %%%02X)\n",
- (unsigned)c);
+ st = r_err(reader,
+ SERD_ERR_BAD_SYNTAX,
+ "invalid IRI character (escape %%%02X)\n",
+ (unsigned)c);
if (reader->strict) {
- *dest = pop_node(reader, *dest);
- return SERD_ERR_BAD_SYNTAX;
+ break;
+ } else {
+ st = SERD_FAILURE;
+ push_byte(reader, *dest, c);
}
- st = SERD_FAILURE;
- push_byte(reader, *dest, c);
} else if (!(c & 0x80)) {
push_byte(reader, *dest, c);
} else if (read_utf8_character(reader, *dest, (uint8_t)c)) {
diff --git a/test/lax/manifest.ttl b/test/lax/manifest.ttl
index e3b11ff4..0cfdb776 100644
--- a/test/lax/manifest.ttl
+++ b/test/lax/manifest.ttl
@@ -7,10 +7,17 @@
rdf:type mf:Manifest ;
rdfs:comment "Serd lax syntax test cases" ;
mf:entries (
+ <#test-bad-string>
<#test-bad-uri>
<#test-bad-utf8>
) .
+<#test-bad-string>
+ rdf:type rdft:TestTurtleNegativeSyntax ;
+ mf:name "test-bad-string" ;
+ mf:action <test-bad-string.ttl> ;
+ mf:result <test-bad-string.nt> .
+
<#test-bad-uri>
rdf:type rdft:TestTurtleNegativeSyntax ;
mf:name "test-bad-uri" ;
diff --git a/test/lax/test-bad-string.nt b/test/lax/test-bad-string.nt
new file mode 100644
index 00000000..24f80a2e
--- /dev/null
+++ b/test/lax/test-bad-string.nt
@@ -0,0 +1 @@
+<http://example.org/s1> <http://example.org/p2> "Good" .
diff --git a/test/lax/test-bad-string.ttl b/test/lax/test-bad-string.ttl
new file mode 100644
index 00000000..72eb9621
--- /dev/null
+++ b/test/lax/test-bad-string.ttl
@@ -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/lax/test-bad-uri.nt b/test/lax/test-bad-uri.nt
index 7458e12a..8cb00ba7 100644
--- a/test/lax/test-bad-uri.nt
+++ b/test/lax/test-bad-uri.nt
@@ -1,3 +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/test_reader_writer.c b/test/test_reader_writer.c
index 573b13de..134c7a8e 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -59,6 +59,7 @@ test_sink(void* handle,
static size_t
eof_test_read(void* buf, size_t size, size_t nmemb, void* stream)
{
+ assert(size == 1);
assert(nmemb == 1);
static const char* const string = "_:s1 <http://example.org/p> _:o1 .\n"