Skip to content

Commit

Permalink
Merge pull request #36 from fkleedorfer/fix-leading-zeros-in-integer-…
Browse files Browse the repository at this point in the history
…literals

Fix leading zeros in integer literals
  • Loading branch information
atextor authored Oct 3, 2024
2 parents c2d1fb1 + 1f34fbb commit 0739515
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private State writeLiteral( final Literal literal, final State state ) {
return state.write( literal.getLexicalForm() );
}
if ( datatypeUri.equals( XSD.integer.getURI() ) ) {
return state.write( literal.getValue().toString() );
return state.write( literal.getLexicalForm() );
}
if ( datatypeUri.equals( RDF.langString.getURI() ) ) {
return state.write( quoteAndEscape( literal ) + "@" + literal.getLanguage() );
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/de/atextor/turtle/formatter/TurtleFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,24 @@ public void testDisableDoubleFormatting() {
assertThat(result.trim()).isEqualTo(modelString);
}

@Test
public void testIntegerLiteralWithLeadingZeros(){
String content = """
@prefix : <http://example.com/ns#> .
:thing :value 060.
""";
String expected = """
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://example.com/ns#> .
:thing :value 060 .""";
final FormattingStyle style = FormattingStyle.DEFAULT;
final TurtleFormatter formatter = new TurtleFormatter(style);
final String result = formatter.applyToContent(content);
assertThat(result.trim()).isEqualTo(expected);
}

private Model modelFromString( final String content ) {
final Model model = ModelFactory.createDefaultModel();
final InputStream stream = new ByteArrayInputStream( content.getBytes( StandardCharsets.UTF_8 ) );
Expand Down

0 comments on commit 0739515

Please sign in to comment.