Skip to content

Commit

Permalink
Issue/51 dot in name (#57)
Browse files Browse the repository at this point in the history
* Allow dot in middle of a prefixed name See #51
* Update test testBad07 accordingly
* Add test to check for bad syntax with dot as last char of QName
* Prevent last char of QName to be a dot
  • Loading branch information
Michiel-s authored Jan 18, 2025
1 parent d50b7c7 commit 0aa3272
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/Parser/Turtle.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,11 @@ protected function parseQNameOrBoolean()
}
$c = $this->read();
}

// 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);
}
}

// Unread last character
Expand Down Expand Up @@ -1217,6 +1222,7 @@ public static function isNameChar($c)
self::isNameStartChar($c)
|| $o >= 0x30 && $o <= 0x39 // 0-9
|| '-' == $c
|| '.' == $c // dots are allowed in the middle of a name, not as start char
|| 0x00B7 == $o;
}

Expand Down
1 change: 0 additions & 1 deletion test/fixtures/turtle/bad-07.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# paths are not in turtle
@prefix : <http://example.org/stuff/1.0/> .
:a.:b.:c .
:a^:b^:c .
9 changes: 9 additions & 0 deletions test/fixtures/turtle/gh51-sweetrdf-dot-in-name-bad.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@prefix : <http://example.org/#> .

# A dot can't be the first nor the last character of the "after the semicolon part of a prefixed name" but is allowed in the middle
# See https://www.w3.org/TR/turtle/#grammar-production-PN_LOCAL
# See https://github.com/sweetrdf/easyrdf/issues/51
# The triples below should not parse!
:SubjectWithEndDot. :predicate :Object .
:Subject :predicateWithEndDot. :Object .
:Subject :predicate :ObjectWithEndDot. .
2 changes: 2 additions & 0 deletions test/fixtures/turtle/gh51-sweetrdf-dot-in-name.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<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> .
7 changes: 7 additions & 0 deletions test/fixtures/turtle/gh51-sweetrdf-dot-in-name.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@prefix : <http://example.org/#> .

# A dot can't be the first nor the last character of the "after the semicolon part of a prefixed name" but is allowed in the middle
# See https://www.w3.org/TR/turtle/#grammar-production-PN_LOCAL
# See https://github.com/sweetrdf/easyrdf/issues/51
:Subject.WithADot :predicate.withADot :Object.WithADot .
:Subject.With.Dots :predicate.with.dots :Object.With.Dots .
21 changes: 20 additions & 1 deletion tests/EasyRdf/Parser/TurtleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public function testBad07()
// paths are not in turtle
$this->expectException('EasyRdf\Parser\Exception');
$this->expectExceptionMessage(
'Turtle Parse Error: object for statement missing on line 3, column 5'
"Turtle Parse Error: expected an RDF value here, found '^' on line 3, column 3"
);
$this->parseTurtle('turtle/bad-07.ttl');
}
Expand Down Expand Up @@ -578,4 +578,23 @@ public function testIssue140()
$this->assertEquals(14, $triple_count);
*/
}

/**
* @see https://github.com/sweetrdf/easyrdf/issues/51
* Notice this is an issue reported in the sweetrdf/easyrdf fork
*/
public function testIssue51()
{
$this->turtleTestCase('gh51-sweetrdf-dot-in-name');
}

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'
);
$this->parseTurtle('turtle/gh51-sweetrdf-dot-in-name-bad.ttl');
}
}

0 comments on commit 0aa3272

Please sign in to comment.