Skip to content

Commit

Permalink
Issue/58 bugfix turtle bool parser (#59)
Browse files Browse the repository at this point in the history
* 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 <hi@inspirito.de>
  • Loading branch information
Michiel-s and k00ni authored Jan 18, 2025
1 parent c573f61 commit c47c72d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Parser/Turtle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/turtle/gh58-sweetrdf-bool-parser.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@prefix : <http://example.org/#> .

# 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.
13 changes: 13 additions & 0 deletions tests/EasyRdf/Parser/TurtleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit c47c72d

Please sign in to comment.