From 8c67f9eba47d30913749e607c440b170a5cbd804 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 15 Apr 2021 17:52:44 -0400 Subject: [WIP] Expand URIs in reader This expands relative and prefixed URIs in the reader on the stack, rather than passing them to the caller to be dealt with. This pushes these context-full forms to the edge of the system as much as possible to minimise the headaches they can cause. Towards having stricter guarantees about nodes and eliminating the CURIE node type altogether. --- test/extra/bad/bad-prefix-dot.ttl | 1 + test/extra/bad/manifest.ttl | 8 ++++- test/extra/full/full-uris.ttl | 6 ++-- test/extra/good/manifest.ttl | 14 ++++++++ test/extra/good/test-local-name-ends-with-dot.nt | 1 + test/extra/good/test-local-name-escapes.nt | 17 +++++++++ test/extra/good/test-local-name-escapes.ttl | 19 ++++++++++ test/meson.build | 1 + test/test_overflow.c | 44 ++++++++++++++++++++---- test/test_reader_writer.c | 2 +- test/test_writer.c | 31 +++++++++++++++++ 11 files changed, 133 insertions(+), 11 deletions(-) create mode 100644 test/extra/bad/bad-prefix-dot.ttl create mode 100644 test/extra/good/test-local-name-ends-with-dot.nt create mode 100644 test/extra/good/test-local-name-escapes.nt create mode 100644 test/extra/good/test-local-name-escapes.ttl (limited to 'test') diff --git a/test/extra/bad/bad-prefix-dot.ttl b/test/extra/bad/bad-prefix-dot.ttl new file mode 100644 index 00000000..7b02211f --- /dev/null +++ b/test/extra/bad/bad-prefix-dot.ttl @@ -0,0 +1 @@ +@prefix dotted.: . diff --git a/test/extra/bad/manifest.ttl b/test/extra/bad/manifest.ttl index cd4aee24..f930b812 100644 --- a/test/extra/bad/manifest.ttl +++ b/test/extra/bad/manifest.ttl @@ -74,8 +74,9 @@ <#bad-object2> <#bad-paths> <#bad-pn-escape> - <#bad-prefix-missing-colon> <#bad-prefix> + <#bad-prefix-dot> + <#bad-prefix-missing-colon> <#bad-quote-in-uri> <#bad-semicolon-after-subject> <#bad-string> @@ -436,6 +437,11 @@ mf:action ; mf:name "bad-prefix-missing-colon" . +<#bad-prefix-dot> + a rdft:TestTurtleNegativeSyntax ; + mf:action ; + mf:name "bad-prefix-dot" . + <#bad-quote-in-uri> a rdft:TestTurtleNegativeSyntax ; mf:action ; diff --git a/test/extra/full/full-uris.ttl b/test/extra/full/full-uris.ttl index cfb048df..dd6c5144 100644 --- a/test/extra/full/full-uris.ttl +++ b/test/extra/full/full-uris.ttl @@ -1,7 +1,7 @@ @prefix eg: . - eg:prefixed false . + false . -eg:s2 - eg:prefixed true . + + true . diff --git a/test/extra/good/manifest.ttl b/test/extra/good/manifest.ttl index 7c356285..11a7ec5e 100644 --- a/test/extra/good/manifest.ttl +++ b/test/extra/good/manifest.ttl @@ -27,6 +27,8 @@ <#test-id> <#test-list-in-blank> <#test-list-subject> + <#test-local-name-ends-with-dot> + <#test-local-name-escapes> <#test-long-backspace-escape> <#test-long-delete-escape> <#test-long-form-feed-escape> @@ -169,6 +171,18 @@ mf:name "test-list-subject" ; mf:result . +<#test-local-name-ends-with-dot> + a rdft:TestTurtleEval ; + mf:action ; + mf:name "test-local-name-ends-with-dot" ; + mf:result . + +<#test-local-name-escapes> + a rdft:TestTurtleEval ; + mf:action ; + mf:name "test-local-name-escapes" ; + mf:result . + <#test-long-backspace-escape> a rdft:TestTurtleEval ; mf:action ; diff --git a/test/extra/good/test-local-name-ends-with-dot.nt b/test/extra/good/test-local-name-ends-with-dot.nt new file mode 100644 index 00000000..3285348a --- /dev/null +++ b/test/extra/good/test-local-name-ends-with-dot.nt @@ -0,0 +1 @@ + . diff --git a/test/extra/good/test-local-name-escapes.nt b/test/extra/good/test-local-name-escapes.nt new file mode 100644 index 00000000..a6362d7a --- /dev/null +++ b/test/extra/good/test-local-name-escapes.nt @@ -0,0 +1,17 @@ + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . diff --git a/test/extra/good/test-local-name-escapes.ttl b/test/extra/good/test-local-name-escapes.ttl new file mode 100644 index 00000000..8c5fce37 --- /dev/null +++ b/test/extra/good/test-local-name-escapes.ttl @@ -0,0 +1,19 @@ +@prefix eg: . + +eg:s eg:p eg:o\' . +eg:s eg:p eg:o\! . +eg:s eg:p eg:o\# . +eg:s eg:p eg:o\$ . +eg:s eg:p eg:o\% . +eg:s eg:p eg:o\& . +eg:s eg:p eg:o\( . +eg:s eg:p eg:o\) . +eg:s eg:p eg:o\* . +eg:s eg:p eg:o\+ . +eg:s eg:p eg:o\, . +eg:s eg:p eg:o\/ . +eg:s eg:p eg:o\; . +eg:s eg:p eg:o\= . +eg:s eg:p eg:o\? . +eg:s eg:p eg:o\@ . +eg:s eg:p eg:o\~ . diff --git a/test/meson.build b/test/meson.build index 01f75b5a..b01dde81 100644 --- a/test/meson.build +++ b/test/meson.build @@ -195,6 +195,7 @@ simple_command_tests = { ['-o'], ['-p'], ['-r'], + ['-s', ' a .'], ['-s'], ['-z'], ], diff --git a/test/test_overflow.c b/test/test_overflow.c index db20f734..9b1a6fb7 100644 --- a/test/test_overflow.c +++ b/test/test_overflow.c @@ -8,7 +8,7 @@ #include #include -static const size_t min_stack_size = 4U * sizeof(size_t) + 240U; +static const size_t min_stack_size = 4U * sizeof(size_t) + 238U; static const size_t max_stack_size = 1024U; static SerdStatus @@ -89,11 +89,9 @@ static void test_turtle_overflow(void) { static const char* const test_strings[] = { - " :%99 .", " .", " " " .", - " eg:foo .", " 1234 .", " (1 2 3 4) .", " (((((((42))))))) .", @@ -111,7 +109,41 @@ test_turtle_overflow(void) "@prefix ug.dot: . \nug.dot:s ug.dot:p ug.dot:o .\n", // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) - "@prefix øøøøøøøøø: . \n" + " " + " " + " .", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + " " + "\"typed\"^^ .", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix eg: .\n" + " " + "\"typed\"^^eg:Datatype .", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix eg: .\n" + " eg:foo .", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix prefix: .\n" + "prefix:subject prefix:predicate prefix:object .\n", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix eg: .\n" + "eg:s eg:p [ eg:p [ eg:p [ eg:p [ eg:p []]]]] .\n", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix eg: .\n" + "eg:s eg:p ( 1 2 3 ( 4 5 6 ( 7 8 9 ) ) ) .\n", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix eg: .\n" + " eg:%99 .", + + // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) + "@prefix øøøøøøøøø: .\n" " øøøøøøøøø:p " "øøøøøøøøø:o .\n", @@ -139,8 +171,8 @@ test_turtle_overflow(void) // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) "@prefix prefix: .\n" - "prefix:subjectthatwillcomearoundtobeingfinishedanycharacternow " - "prefix:predicate prefix:object .\n", + " " + "prefix:predicate prefix:object ; prefix:p prefix:o .\n", // NOLINTNEXTLINE(bugprone-suspicious-missing-comma) "@prefix eg: .\n" diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 3a20bb7a..55c4b584 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -100,7 +100,7 @@ test_write_errors(void) SerdWorld* const world = serd_world_new(); ErrorContext ctx = {0U, 0U}; - const size_t max_offsets[] = {0, 373, 1911, 2003, 414}; + const size_t max_offsets[] = {0, 368, 1900, 1992, 413}; // Test errors at different offsets to hit different code paths for (unsigned s = 1; s <= (unsigned)SERD_TRIG; ++s) { diff --git a/test/test_writer.c b/test/test_writer.c index f76cc800..ee602044 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -406,6 +406,36 @@ test_write_pname_escapes(void) check_pname_escape((const char*)last_escape, "eg:s\n\teg:p eg:wx%C3%B7 .\n"); } +static void +test_write_bad_uri(void) +{ + SerdWorld* world = serd_world_new(); + SerdEnv* env = serd_env_new(serd_empty_string()); + SerdNode* s = serd_new_uri(serd_string("http://example.org/s")); + SerdNode* p = serd_new_uri(serd_string("http://example.org/p")); + SerdNode* rel = serd_new_uri(serd_string("rel")); + SerdBuffer buffer = {NULL, 0}; + SerdOutputStream output = serd_open_output_buffer(&buffer); + SerdWriter* writer = + serd_writer_new(world, SERD_NTRIPLES, 0U, env, &output, 1); + + assert(writer); + + const SerdStatus st = + serd_sink_write(serd_writer_sink(writer), 0U, s, p, rel, NULL); + assert(st); + assert(st == SERD_BAD_ARG); + + serd_writer_free(writer); + serd_close_output(&output); + serd_free(buffer.buf); + serd_node_free(rel); + serd_node_free(p); + serd_node_free(s); + serd_env_free(env); + serd_world_free(world); +} + int main(void) { @@ -418,6 +448,7 @@ main(void) test_writer_stack_overflow(); test_write_empty_syntax(); test_write_pname_escapes(); + test_write_bad_uri(); return 0; } -- cgit v1.2.1