Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/51 dot in name #57

Merged
merged 5 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
Loading