summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Beckett <dave@dajobe.org>2014-10-26 20:26:41 -0700
committerDave Beckett <dave@dajobe.org>2014-10-26 20:26:53 -0700
commite44eac50d51809f7ab6caf122cac80e0adb58c8b (patch)
treeba0a1a54eb9f64afd261603dfa4dbb07a466b306
parent899a7137c650b6db9ff8692d00429479ec4c9fdd (diff)
downloadraptor-e44eac50d51809f7ab6caf122cac80e0adb58c8b.tar.gz
Accept '_' as alias/typo for '-' in lang strings. Replace on parsing.
Fixes Issue #0000574 http://bugs.librdf.org/mantis/view.php?id=574
-rw-r--r--src/raptor_ntriples.c9
-rw-r--r--src/raptor_term.c13
-rw-r--r--tests/ntriples/Makefile.am6
-rw-r--r--tests/ntriples/bug-574.nt1
-rw-r--r--tests/ntriples/bug-574.out1
5 files changed, 24 insertions, 6 deletions
diff --git a/src/raptor_ntriples.c b/src/raptor_ntriples.c
index 50154ecc..e23debd9 100644
--- a/src/raptor_ntriples.c
+++ b/src/raptor_ntriples.c
@@ -87,10 +87,12 @@ raptor_ntriples_term_valid(unsigned char c, int position,
break;
case RAPTOR_TERM_CLASS_LANGUAGE:
- /* ends on first non [a-zA-Z]+ ('-' [a-zA-Z0-9]+ )? */
+ /* ends on first non [a-zA-Z]+ ('-' [a-zA-Z0-9]+ )?
+ * Accept _ as synonym / typo for -.
+ */
result = IS_ASCII_ALPHA(c);
if(position)
- result = (result || IS_ASCII_DIGIT(c) || c == '-');
+ result = (result || IS_ASCII_DIGIT(c) || c == '-' || c == '_');
break;
default:
@@ -575,10 +577,13 @@ raptor_ntriples_parse_term(raptor_world* world, raptor_locator* locator,
/* Normalize language to lowercase
* http://www.w3.org/TR/rdf-concepts/#dfn-language-identifier
+ * Also convert _ to - as synonym / typo.
*/
for(q = object_literal_language; *q; q++) {
if(IS_ASCII_UPPER(*q))
*q = TO_ASCII_LOWER(*q);
+ if(*q == '_')
+ *q = '-';
}
}
diff --git a/src/raptor_term.c b/src/raptor_term.c
index d64da8fc..d6fa52b2 100644
--- a/src/raptor_term.c
+++ b/src/raptor_term.c
@@ -199,13 +199,22 @@ raptor_new_term_from_counted_literal(raptor_world* world,
*new_literal = '\0';
if(language) {
+ unsigned char c;
+ unsigned char* l;
+
new_language = RAPTOR_MALLOC(unsigned char*, language_len + 1);
if(!new_language) {
RAPTOR_FREE(char*, new_literal);
return NULL;
}
- memcpy(new_language, language, language_len);
- new_language[language_len] = '\0';
+
+ l = new_language;
+ while((c = *language++)) {
+ if(c == '_')
+ c = '-';
+ *l++ = c;
+ }
+ *l = '\0';
} else
language_len = 0;
diff --git a/tests/ntriples/Makefile.am b/tests/ntriples/Makefile.am
index 18f025cb..15b34cf8 100644
--- a/tests/ntriples/Makefile.am
+++ b/tests/ntriples/Makefile.am
@@ -26,14 +26,16 @@ nt2013-ex1.nt \
nt2013-ex2.nt \
nt2013-ex3.nt \
nt2013-ex4.nt \
-bug-562.nt
+bug-562.nt \
+bug-574.nt
NT_OUT_FILES = test.out \
nt2013-ex1.out \
nt2013-ex2.out \
nt2013-ex3.out \
nt2013-ex4.out \
-bug-562.out
+bug-562.out \
+bug-574.out
NT_BAD_TEST_FILES=bad-00.nt bad-02.nt bad-03.nt bad-04.nt \
bad-05.nt bad-06.nt bad-07.nt
diff --git a/tests/ntriples/bug-574.nt b/tests/ntriples/bug-574.nt
new file mode 100644
index 00000000..9f204971
--- /dev/null
+++ b/tests/ntriples/bug-574.nt
@@ -0,0 +1 @@
+<http://example.org/resource> <http://www.w3.org/2000/01/rdf-schema#label> "SOMETHING"@zh_pinyin .
diff --git a/tests/ntriples/bug-574.out b/tests/ntriples/bug-574.out
new file mode 100644
index 00000000..09aa702e
--- /dev/null
+++ b/tests/ntriples/bug-574.out
@@ -0,0 +1 @@
+<http://example.org/resource> <http://www.w3.org/2000/01/rdf-schema#label> "SOMETHING"@zh-pinyin .