Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/310918
Change subject: Fix escaping \a and \v which should be numeric in n3/turtle
......................................................................
Fix escaping \a and \v which should be numeric in n3/turtle
Bug: T145757
Change-Id: Ia1dc5a0411b3b6465eca25126fc1ea4d97ec71a2
---
M src/N3Quoter.php
M tests/phpunit/N3QuoterTest.php
2 files changed, 61 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/18/310918/1
diff --git a/src/N3Quoter.php b/src/N3Quoter.php
index ee85c34..82152ed 100644
--- a/src/N3Quoter.php
+++ b/src/N3Quoter.php
@@ -39,14 +39,56 @@
) );
}
- public function escapeLiteral( $s ) {
- $escaped = addcslashes( $s, "\x0..\x1F\"\\" );
+ public function escapeLiteral( $s ) {
+ // String escapes. Note that the N3 spec is more restrictive than the
Turtle and TR
+ // specifications, see <https://www.w3.org/TeamSubmission/n3/#escaping>
+ // and <https://www.w3.org/TR/turtle/#string>
+ // and <https://www.w3.org/TR/n-triples/#grammar-production-literal>.
+ // Allowed escapes according to the N3 spec are:
+ // ECHAR ::= '\' [tbnrf"'\]
+ // The single quote however does not require escaping when used in
double quotes.
+ $escaped = strtr( $s, array(
+ "\x00" => '\u0000',
+ "\x01" => '\u0001',
+ "\x02" => '\u0002',
+ "\x03" => '\u0003',
+ "\x04" => '\u0004',
+ "\x05" => '\u0005',
+ "\x06" => '\u0006',
+ "\x07" => '\u0007',
+ "\x08" => '\b',
+ "\x09" => '\t',
+ "\x0A" => '\n',
+ "\x0B" => '\u000B',
+ "\x0C" => '\f',
+ "\x0D" => '\r',
+ "\x0E" => '\u000E',
+ "\x0F" => '\u000F',
+ "\x10" => '\u0010',
+ "\x11" => '\u0011',
+ "\x12" => '\u0012',
+ "\x13" => '\u0013',
+ "\x14" => '\u0014',
+ "\x15" => '\u0015',
+ "\x16" => '\u0016',
+ "\x17" => '\u0017',
+ "\x18" => '\u0018',
+ "\x19" => '\u0019',
+ "\x1A" => '\u001A',
+ "\x1B" => '\u001B',
+ "\x1C" => '\u001C',
+ "\x1D" => '\u001D',
+ "\x1E" => '\u001E',
+ "\x1F" => '\u001F',
+ '"' => '\"',
+ '\\' => '\\\\',
+ ) );
- if ( $this->escaper !== null ) {
- $escaped = $this->escaper->escapeString( $escaped );
- }
+ if ( $this->escaper !== null ) {
+ $escaped = $this->escaper->escapeString( $escaped );
+ }
- return $escaped;
- }
+ return $escaped;
+ }
}
diff --git a/tests/phpunit/N3QuoterTest.php b/tests/phpunit/N3QuoterTest.php
index c65203a..df977c4 100644
--- a/tests/phpunit/N3QuoterTest.php
+++ b/tests/phpunit/N3QuoterTest.php
@@ -51,15 +51,18 @@
$this->assertEquals( $expected, $quoter->escapeIRI( $iri ) );
}
- public function provideEscapeLiteral() {
- return array(
- array( 'Hello World', 'Hello World' ),
- array( "Hello\nWorld", 'Hello\nWorld' ),
- array( "Hello\tWorld", 'Hello\tWorld' ),
- array( 'Hällo Wörld', 'Hällo Wörld', false ),
- array( 'Hällo Wörld', 'H\u00E4llo W\u00F6rld', true ),
- );
- }
+ public function provideEscapeLiteral() {
+ return array(
+ array( "Hello World", 'Hello World' ),
+ array( "Hello\nWorld", 'Hello\nWorld' ),
+ array( "Hello\tWorld", 'Hello\tWorld' ),
+ array( "Hällo Wörld", 'Hällo Wörld', false ),
+ array( "Hällo Wörld", 'H\u00E4llo W\u00F6rld', true ),
+ array( '\a', '\\\\a' ),
+ array( "\x7\v\0\x1F", '\u0007\u000B\u0000\u001F' ),
+
+ );
+ }
/**
* @dataProvider provideEscapeLiteral
--
To view, visit https://gerrit.wikimedia.org/r/310918
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia1dc5a0411b3b6465eca25126fc1ea4d97ec71a2
Gerrit-PatchSet: 1
Gerrit-Project: purtle
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits