Skip to content

Commit 9bc91f7

Browse files
author
Marco De Salvo
committed
Apply patch for parsing of Turtle integer/literal + dot at EOF
1 parent 69ec14f commit 9bc91f7

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

RDFSharp.Test/Model/Serializers/RDFTurtleTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8782,6 +8782,33 @@ public void ShouldDeserializeGraphWithManyTriples()
87828782
Assert.IsTrue(graph.ContainsTriple(new RDFTriple(new RDFResource("http://subj/"), new RDFResource("http://pred2/"), new RDFResource("http://obj2/"))));
87838783
}
87848784

8785+
//E2E: RDF4J-5407
8786+
8787+
[TestMethod]
8788+
public void ShouldDeserializeTripleEndingWithDigitAndDotEOF()
8789+
{
8790+
MemoryStream stream = new MemoryStream();
8791+
using (StreamWriter writer = new StreamWriter(stream))
8792+
writer.WriteLine($"@base <{RDFNamespaceRegister.DefaultNamespace}>.{Environment.NewLine}:alice :age 30.");
8793+
RDFGraph graph = RDFTurtle.Deserialize(new MemoryStream(stream.ToArray()), null);
8794+
8795+
Assert.IsNotNull(graph);
8796+
Assert.AreEqual(1, graph.TriplesCount);
8797+
Assert.IsTrue(graph.ContainsTriple(new RDFTriple(new RDFResource($"{RDFNamespaceRegister.DefaultNamespace}alice"), new RDFResource($"{RDFNamespaceRegister.DefaultNamespace}age"), new RDFTypedLiteral("30", RDFModelEnums.RDFDatatypes.XSD_INTEGER))));
8798+
}
8799+
[TestMethod]
8800+
public void ShouldDeserializeTripleEndingWithLetterAndDotEOF()
8801+
{
8802+
MemoryStream stream = new MemoryStream();
8803+
using (StreamWriter writer = new StreamWriter(stream))
8804+
writer.WriteLine($"@base <{RDFNamespaceRegister.DefaultNamespace}>.{Environment.NewLine}:alice :age \"a\".");
8805+
RDFGraph graph = RDFTurtle.Deserialize(new MemoryStream(stream.ToArray()), null);
8806+
8807+
Assert.IsNotNull(graph);
8808+
Assert.AreEqual(1, graph.TriplesCount);
8809+
Assert.IsTrue(graph.ContainsTriple(new RDFTriple(new RDFResource($"{RDFNamespaceRegister.DefaultNamespace}alice"), new RDFResource($"{RDFNamespaceRegister.DefaultNamespace}age"), new RDFPlainLiteral("a"))));
8810+
}
8811+
87858812
[TestCleanup]
87868813
public void Cleanup()
87878814
{

RDFSharp/Model/Serializers/RDFTurtle.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,11 @@ internal static RDFTypedLiteral ParseNumber(string turtleData, RDFTurtleContext
836836
// read optional fractional digits
837837
if (bufChar == '.')
838838
{
839-
if (IsWhitespace(PeekCodePoint(turtleData, turtleContext)))
839+
int next = PeekCodePoint(turtleData, turtleContext);
840+
// Treat '.' as statement terminator at EOF only when we already parsed at least one digit
841+
// (e.g., "30.") or when whitespace follows. Otherwise, attempt to parse as decimal
842+
// which will surface a useful error for a stray '.' token.
843+
if ((value.Length > 0 && next == -1) || IsWhitespace(PeekCodePoint(turtleData, turtleContext)))
840844
{
841845
// We're parsing an integer that did not have a space before the period to end the statement
842846
}

0 commit comments

Comments
 (0)