Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leading zeros in integer literals #36

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading