From f42130dc7188f89f5fc9539e3be0dc854145dd77 Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Tue, 28 Jan 2025 19:31:07 +0100 Subject: [PATCH] Issue/51 dot last char (#60) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * DonĀ“t throw exception but return ending dot to input buffer * Update test * Add test for name with dot as last char --- lib/Parser/Turtle.php | 5 ++++- test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out | 1 + test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl | 3 +++ tests/EasyRdf/Parser/TurtleTest.php | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Parser/Turtle.php b/lib/Parser/Turtle.php index 1368d396..ad414edd 100644 --- a/lib/Parser/Turtle.php +++ b/lib/Parser/Turtle.php @@ -948,7 +948,10 @@ protected function parseQNameOrBoolean() // Last char of name must not be a dot if (mb_substr($localName, -1) === '.') { - throw new Exception("Turtle Parse Error: last character of QName must not be a dot", $this->line, $this->column - 1); + $localName = substr_replace($localName, '', -1); + $this->unread($c); // step back + $this->unread('.'); // return dot to input buffer + $c = $this->read(); // read, because below the unread($c) is done for all cases } } diff --git a/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out b/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out index f1bee29f..521cb92c 100644 --- a/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out +++ b/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out @@ -1,2 +1,3 @@ . . + . diff --git a/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl b/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl index 502bc150..512979b3 100644 --- a/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl +++ b/test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl @@ -5,3 +5,6 @@ # See https://github.com/sweetrdf/easyrdf/issues/51 :Subject.WithADot :predicate.withADot :Object.WithADot . :Subject.With.Dots :predicate.with.dots :Object.With.Dots . + +# A dot as last char is not part of the name but parsed as statement ending +:sub :pred :Object.WithADot. diff --git a/tests/EasyRdf/Parser/TurtleTest.php b/tests/EasyRdf/Parser/TurtleTest.php index ffbcf7c1..d7799f79 100644 --- a/tests/EasyRdf/Parser/TurtleTest.php +++ b/tests/EasyRdf/Parser/TurtleTest.php @@ -594,7 +594,7 @@ public function testIssue51Bad() // Test long literals with missing end $this->expectException('EasyRdf\Parser\Exception'); $this->expectExceptionMessage( - 'Turtle Parse Error: last character of QName must not be a dot on line 7, column 20' + 'Turtle Parse Error: Illegal predicate type: literal on line 7, column 19' ); $this->parseTurtle('turtle/gh51-sweetrdf-dot-in-name-bad.ttl'); }