aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--src/env.c38
-rw-r--r--src/reader.c5
3 files changed, 41 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5337a87a..2bc39b71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
serd (UNRELEASED) unstable; urgency=low
* Fix pretty printing of successive blank descriptions, i.e. "] , ["
+ * Avoid writing illegal Turtle names as a result of URI qualifying
-- David Robillard <d@drobilla.net> UNRELEASED
diff --git a/src/env.c b/src/env.c
index 4ce28329..f7204121 100644
--- a/src/env.c
+++ b/src/env.c
@@ -152,6 +152,41 @@ serd_env_set_prefix(SerdEnv* env,
return SERD_SUCCESS;
}
+static inline bool
+is_nameStartChar(const uint8_t c)
+{
+ // TODO: not strictly correct (see reader.c read_nameStartChar)
+ return (c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z');
+}
+
+static inline bool
+is_nameChar(const uint8_t c)
+{
+ // TODO: 0x300-0x036F | 0x203F-0x2040 (see reader.c read_nameChar)
+ return is_nameStartChar(c) || c == '-'
+ || (c >= '0' && c <= '9') || c == 0xB7;
+}
+
+/**
+ Return true iff @c buf is a valid Turtle name.
+*/
+static inline bool
+is_name(const uint8_t* buf,
+ size_t len)
+{
+ if (!is_nameStartChar(buf[0])) {
+ return false;
+ }
+
+ for (size_t i = 1; i < len; ++i) {
+ if (!is_nameChar(buf[i])) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
SERD_API
bool
serd_env_qualify(const SerdEnv* env,
@@ -168,6 +203,9 @@ serd_env_qualify(const SerdEnv* env,
*prefix_name = env->prefixes[i].name;
suffix->buf = uri->buf + prefix_uri->n_bytes;
suffix->len = uri->n_bytes - prefix_uri->n_bytes;
+ if (!is_name(suffix->buf, suffix->len)) {
+ continue;
+ }
return true;
}
}
diff --git a/src/reader.c b/src/reader.c
index e08956ef..24802164 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -711,7 +711,7 @@ static inline uchar
read_nameStartChar(SerdReader* reader, bool required)
{
const uint8_t c = peek_byte(reader);
- if (c == '_' || is_alpha(c)) {
+ if (c == '_' || is_alpha(c)) { // TODO: not strictly correct
return eat_byte(reader, c);
} else {
if (required) {
@@ -734,8 +734,7 @@ read_nameChar(SerdReader* reader)
case '-': case 0xB7: case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return eat_byte(reader, c);
- default:
- // TODO: 0x300-0x036F | 0x203F-0x2040
+ default: // TODO: 0x300-0x036F | 0x203F-0x2040
return 0;
}
return 0;