aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--src/n3.c3
-rw-r--r--src/serdi.c4
-rw-r--r--src/string_utils.h16
-rw-r--r--test/meson.build5
5 files changed, 19 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 372e20fe..7813fff9 100644
--- a/NEWS
+++ b/NEWS
@@ -2,13 +2,14 @@ serd (0.32.3) unstable; urgency=medium
* Clean up enum declarations
* Fix library current_version on MacOS
+ * Fix overly permissive parsing of syntax names on the command line
* Fix parsing NQuads lines with no space before the final dot
* Gracefully handle errors while writing the end of anonymous nodes
* Support reading lone lists in lax mode
* Treat out of range unicode characters as errors
* Write blank lines between graphs and statements in TriG
- -- David Robillard <d@drobilla.net> Mon, 24 Jun 2024 14:01:08 +0000
+ -- David Robillard <d@drobilla.net> Mon, 24 Jun 2024 16:44:31 +0000
serd (0.32.2) stable; urgency=medium
diff --git a/src/n3.c b/src/n3.c
index 6cb8522e..a3cb93a6 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1599,7 +1599,8 @@ tokcmp(SerdReader* const reader,
return -1;
}
- return serd_strncasecmp((const char*)node->buf, tok, n);
+ assert(node->buf[node->n_bytes] == '\0');
+ return serd_strcasecmp((const char*)node->buf, tok);
}
SerdStatus
diff --git a/src/serdi.c b/src/serdi.c
index 2bea9e3a..9d0a8f44 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -44,7 +44,7 @@ static SerdSyntax
get_syntax(const char* const name)
{
for (const Syntax* s = syntaxes; s->name; ++s) {
- if (!serd_strncasecmp(s->name, name, strlen(name))) {
+ if (!serd_strcasecmp(s->name, name)) {
return s->syntax;
}
}
@@ -59,7 +59,7 @@ guess_syntax(const char* const filename)
const char* ext = strrchr(filename, '.');
if (ext) {
for (const Syntax* s = syntaxes; s->name; ++s) {
- if (!serd_strncasecmp(s->extension, ext, strlen(ext))) {
+ if (!serd_strcasecmp(s->extension, ext)) {
return s->syntax;
}
}
diff --git a/src/string_utils.h b/src/string_utils.h
index 7770e1eb..4babee63 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -101,16 +101,20 @@ serd_to_upper(const char c)
return (char)((c >= 'a' && c <= 'z') ? c - 32 : c);
}
-static inline int
-serd_strncasecmp(const char* s1, const char* s2, size_t n)
+SERD_PURE_FUNC static inline int
+serd_strcasecmp(const char* s1, const char* s2)
{
- for (; n > 0 && *s2; s1++, s2++, --n) {
- if (serd_to_upper(*s1) != serd_to_upper(*s2)) {
- return ((*(const uint8_t*)s1 < *(const uint8_t*)s2) ? -1 : +1);
+ while (*s1 && *s2) {
+ const char c1 = serd_to_upper(*s1++);
+ const char c2 = serd_to_upper(*s2++);
+ if (c1 != c2) {
+ return (c1 < c2) ? -1 : +1;
}
}
- return 0;
+ const char c1 = serd_to_upper(*s1);
+ const char c2 = serd_to_upper(*s2);
+ return (c1 == c2) ? 0 : (c1 < c2) ? -1 : +1;
}
static inline uint32_t
diff --git a/test/meson.build b/test/meson.build
index 0ea7f1a2..fe476491 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -155,9 +155,10 @@ simple_command_tests = {
['-c'],
['-fi'],
['-i', 'turtle'],
- ['-i', 'unknown'],
+ ['-i', 'turt'],
['-i'],
- ['-o', 'unknown'],
+ ['-o', '~unknown'],
+ ['-o', 'ntripleses'],
['-o'],
['-p'],
['-r'],