From c47c72d2216eec102ae2f8693ce6505c61f1c08e Mon Sep 17 00:00:00 2001 From: Michiel Stornebrink Date: Sat, 18 Jan 2025 10:09:35 +0100 Subject: [PATCH] Issue/58 bugfix turtle bool parser (#59) * Bugfix parsing boolean values in Turtle: Case where boolean value is directly followed by other char without whitespace. Fixes #58 --------- Co-authored-by: Konrad Abicht --- lib/Parser/Turtle.php | 3 +++ test/fixtures/turtle/gh58-sweetrdf-bool-parser.ttl | 11 +++++++++++ tests/EasyRdf/Parser/TurtleTest.php | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/fixtures/turtle/gh58-sweetrdf-bool-parser.ttl diff --git a/lib/Parser/Turtle.php b/lib/Parser/Turtle.php index f9785bde..1368d396 100644 --- a/lib/Parser/Turtle.php +++ b/lib/Parser/Turtle.php @@ -906,6 +906,9 @@ protected function parseQNameOrBoolean() $value = $prefix; if ('true' == $value || 'false' == $value) { + // Unread last character + $this->unread($c); + return [ 'type' => 'literal', 'value' => $value, diff --git a/test/fixtures/turtle/gh58-sweetrdf-bool-parser.ttl b/test/fixtures/turtle/gh58-sweetrdf-bool-parser.ttl new file mode 100644 index 00000000..76a5099a --- /dev/null +++ b/test/fixtures/turtle/gh58-sweetrdf-bool-parser.ttl @@ -0,0 +1,11 @@ +@prefix : . + +# Allow reserved chars directly after boolean values (no whitespace) +# See https://github.com/sweetrdf/easyrdf/issues/58 +:foo :bar true. + +:foo :bar false; + :bar :baz ; +. + +:foo :bar true,false. diff --git a/tests/EasyRdf/Parser/TurtleTest.php b/tests/EasyRdf/Parser/TurtleTest.php index b0a880b1..ffbcf7c1 100644 --- a/tests/EasyRdf/Parser/TurtleTest.php +++ b/tests/EasyRdf/Parser/TurtleTest.php @@ -608,4 +608,17 @@ public function testIssue52() { $this->turtleTestCase('gh52-sweetrdf-whitespace-langtag'); } + + /** + * Bug in Turtle parser for boolean value that is directly followed by a semicolon + * + * @see https://github.com/sweetrdf/easyrdf/issues/58 + */ + public function testIssue58() + { + // Test file should parse without exceptions + $this->expectNotToPerformAssertions(); + + $this->parseTurtle('turtle/gh58-sweetrdf-bool-parser.ttl'); + } }