Skip to content

Commit

Permalink
Issue/51 dot last char (#60)
Browse files Browse the repository at this point in the history
* Don´t throw exception but return ending dot to input buffer

* Update test

* Add test for name with dot as last char
  • Loading branch information
Michiel-s authored Jan 28, 2025
1 parent a6e435f commit f42130d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/Parser/Turtle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<http://example.org/#Subject.WithADot> <http://example.org/#predicate.withADot> <http://example.org/#Object.WithADot> .
<http://example.org/#Subject.With.Dots> <http://example.org/#predicate.with.dots> <http://example.org/#Object.With.Dots> .
<http://example.org/#sub> <http://example.org/#pred> <http://example.org/#Object.WithADot> .
3 changes: 3 additions & 0 deletions test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion tests/EasyRdf/Parser/TurtleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit f42130d

Please sign in to comment.