aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-01 14:34:42 +0200
committerDavid Robillard <d@drobilla.net>2018-06-10 17:19:53 +0000
commit480744aab736a669c548cb5ced68866c3ebffb4e (patch)
tree6b2508b197bc74a7ea4747bfc7efe98cdee271a8 /src/writer.c
parenta9efdc83455ccd27a505a29802277e7ef02dd120 (diff)
downloadserd-480744aab736a669c548cb5ced68866c3ebffb4e.tar.gz
serd-480744aab736a669c548cb5ced68866c3ebffb4e.tar.bz2
serd-480744aab736a669c548cb5ced68866c3ebffb4e.zip
Remove syntax assumptions from SerdEnv implementation
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/writer.c b/src/writer.c
index 603ca65e..5d63b581 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -462,6 +462,19 @@ write_literal(SerdWriter* writer,
return true;
}
+// Return true iff `buf` is a valid prefixed name suffix
+static inline bool
+is_name(const uint8_t* buf, const size_t len)
+{
+ // TODO: This is more strict than it should be.
+ for (size_t i = 0; i < len; ++i) {
+ if (!(is_alpha(buf[i]) || is_digit(buf[i]))) {
+ return false;
+ }
+ }
+ return true;
+}
+
static bool
write_uri_node(SerdWriter* const writer,
const SerdNode* node,
@@ -485,7 +498,8 @@ write_uri_node(SerdWriter* const writer,
&& !strcmp((const char*)node->buf, NS_RDF "nil")) {
return sink("()", 2, writer) == 2;
} else if (has_scheme && (writer->style & SERD_STYLE_CURIED) &&
- serd_env_qualify(writer->env, node, &prefix, &suffix)) {
+ serd_env_qualify(writer->env, node, &prefix, &suffix) &&
+ is_name(suffix.buf, suffix.len)) {
write_uri(writer, prefix.buf, prefix.n_bytes);
sink(":", 1, writer);
write_uri(writer, suffix.buf, suffix.len);