Skip to content

Commit 3e497d3

Browse files
authored
Merge pull request #12 from filip26/fix/11-an-i18n-datatype-with-no-language-but-a-direction-produced-an-empty-language-tag-instead-of-null
Fix/11 an i18n datatype with no language but a direction produced an empty language tag instead of null
2 parents d6935fd + 0b1437c commit 3e497d3

6 files changed

Lines changed: 116 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ var encodedLiteral = NQuadsWriter.literal(...);
4040
<dependency>
4141
<groupId>com.apicatalog</groupId>
4242
<artifactId>titanium-rdf-n-quads</artifactId>
43-
<version>1.0.1</version>
43+
<version>1.0.2</version>
4444
</dependency>
4545
```
4646

4747
### Gradle
4848

4949
```gradle
50-
implementation("com.apicatalog:titanium-rdf-n-quads:1.0.1")
50+
implementation("com.apicatalog:titanium-rdf-n-quads:1.0.2")
5151
```
5252

5353
## Contributing

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.apicatalog</groupId>
77
<artifactId>titanium-rdf-n-quads</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.0.2</version>
99
<packaging>jar</packaging>
1010
<url>https://github.com/filip26/titanium-rdf-n-quads</url>
1111
<scm>

src/main/java/com/apicatalog/rdf/nquads/NQuadsReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ protected void object() throws NQuadsReaderException {
279279
datatype(datatype, (a, b) -> {
280280
this.ltDatatype = a;
281281
if (b != null) {
282-
if (b.length > 1) {
282+
if (b.length > 1 && b[1] != null && !b[1].trim().isEmpty()) {
283283
this.ltDirection = b[1];
284284
}
285-
if (b.length > 0) {
285+
if (b.length > 0 && b[0] != null && !b[0].trim().isEmpty()) {
286286
this.ltLangTag = b[0];
287287
}
288288
}

src/main/java/com/apicatalog/rdf/nquads/NQuadsWriter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,11 @@ protected static final void literal(Writer writer, String object, String datatyp
247247
writer.append('"').append(NQuadsAlphabet.escape(object)).append('"');
248248

249249
if (direction != null) {
250-
writer.append(NQuadsAlphabet.I18N_BASE)
251-
.append(langTag)
252-
.append("_")
253-
.append(direction);
250+
writer.append(NQuadsAlphabet.I18N_BASE);
251+
if (langTag != null) {
252+
writer.append(langTag);
253+
}
254+
writer.append("_").append(direction);
254255

255256
} else if (langTag != null) {
256257

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.apicatalog.rdf.nquads;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNull;
5+
6+
import java.io.StringReader;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import com.apicatalog.rdf.api.RdfConsumerException;
11+
12+
class NQuadsReaderTest {
13+
14+
@Test
15+
void testI18NLang() throws NQuadsReaderException, RdfConsumerException {
16+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#de> ."))
17+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
18+
assertEquals("c", object);
19+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
20+
assertEquals("de", language);
21+
assertNull(direction);
22+
assertNull(graph);
23+
return null;
24+
});
25+
}
26+
27+
@Test
28+
void testI18NDirection() throws NQuadsReaderException, RdfConsumerException {
29+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#_rtl> ."))
30+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
31+
assertEquals("c", object);
32+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
33+
assertNull(language);
34+
assertEquals("rtl", direction);
35+
assertNull(graph);
36+
return null;
37+
});
38+
}
39+
40+
@Test
41+
void testI18NEmptyDirection() throws NQuadsReaderException, RdfConsumerException {
42+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#cz_> ."))
43+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
44+
assertEquals("c", object);
45+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
46+
assertEquals("cz", language);
47+
assertNull(direction);
48+
assertNull(graph);
49+
return null;
50+
});
51+
}
52+
53+
@Test
54+
void testI18NEmptyLang() throws NQuadsReaderException, RdfConsumerException {
55+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#_ltr> ."))
56+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
57+
assertEquals("c", object);
58+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
59+
assertNull(language);
60+
assertEquals("ltr", direction);
61+
assertNull(graph);
62+
return null;
63+
});
64+
}
65+
66+
@Test
67+
void testI18() throws NQuadsReaderException, RdfConsumerException {
68+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#> ."))
69+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
70+
assertEquals("c", object);
71+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
72+
assertNull(language);
73+
assertNull(direction);
74+
assertNull(graph);
75+
return null;
76+
});
77+
}
78+
79+
@Test
80+
void testI18NEmpty() throws NQuadsReaderException, RdfConsumerException {
81+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#_> ."))
82+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
83+
assertEquals("c", object);
84+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
85+
assertNull(language);
86+
assertNull(direction);
87+
assertNull(graph);
88+
return null;
89+
});
90+
}
91+
92+
@Test
93+
void testI18NDirLangTag() throws NQuadsReaderException, RdfConsumerException {
94+
new NQuadsReader(new StringReader("<test:a> <test:b> \"c\"^^<https://www.w3.org/ns/i18n#cz_ltr> ."))
95+
.provide((subject, predicate, object, datatype, language, direction, graph) -> {
96+
assertEquals("c", object);
97+
assertEquals("https://www.w3.org/ns/i18n#", datatype);
98+
assertEquals("cz", language);
99+
assertEquals("ltr", direction);
100+
assertNull(graph);
101+
return null;
102+
});
103+
}
104+
}

src/test/java/com/apicatalog/rdf/nquads/NQuadsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ void testReadWrite(NQuadsTestCase testCase) throws IOException, URISyntaxExcepti
6767

6868
try (final InputStream out = NQuadsTest.class.getResourceAsStream(TEST_CASE_BASE_PATH + testCase.getName() + ".out.nq")) {
6969
if (out != null) {
70-
expected = isToString(out);
70+
expected = isToString(out);
7171
}
7272
}
73-
73+
7474
final boolean match = expected.equals(result);
7575

7676
if (!match) {

0 commit comments

Comments
 (0)