Smalyshev has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/332816 )
Change subject: Do not double-quote quotes in NTriples format ...................................................................... Do not double-quote quotes in NTriples format Bug: T154531 Change-Id: I9f9ed50e083542191c8eecfeff4a56920e34f0e5 --- M src/UnicodeEscaper.php A tests/data/TextWithSpecialChars.nt A tests/data/TextWithSpecialChars.rdf A tests/data/TextWithSpecialChars.ttl M tests/phpunit/RdfWriterTestBase.php 5 files changed, 30 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/16/332816/1 diff --git a/src/UnicodeEscaper.php b/src/UnicodeEscaper.php index d10f717..e2660f1 100644 --- a/src/UnicodeEscaper.php +++ b/src/UnicodeEscaper.php @@ -100,16 +100,8 @@ return '\r'; /* #xD (13) */ } elseif ( $no < 32 ) { return '\u' . sprintf( '%04X', $no ); /* #xE-#x1F (14-31) */ - } elseif ( $no < 34 ) { - return $c; /* #x20-#x21 (32-33) */ - } elseif ( $no == 34 ) { - return '\"'; /* #x22 (34) */ - } elseif ( $no < 92 ) { - return $c; /* #x23-#x5B (35-91) */ - } elseif ( $no == 92 ) { - return '\\'; /* #x5C (92) */ } elseif ( $no < 127 ) { - return $c; /* #x5D-#x7E (93-126) */ + return $c; /* #x20-#x7E (32-126) */ } elseif ( $no < 65536 ) { return '\u' . sprintf( '%04X', $no ); /* #x7F-#xFFFF (128-65535) */ } elseif ( $no < 1114112 ) { diff --git a/tests/data/TextWithSpecialChars.nt b/tests/data/TextWithSpecialChars.nt new file mode 100644 index 0000000..1ab33ec --- /dev/null +++ b/tests/data/TextWithSpecialChars.nt @@ -0,0 +1,2 @@ +<http://www.example.org/terms/Duck> <http://www.example.org/terms/says> "Duck says: \"Quack!\"" . +<http://www.example.org/terms/Cow> <http://www.example.org/terms/says> "Cow says:\n\r 'Moo! \\Moo!'" . diff --git a/tests/data/TextWithSpecialChars.rdf b/tests/data/TextWithSpecialChars.rdf new file mode 100644 index 0000000..96d3320 --- /dev/null +++ b/tests/data/TextWithSpecialChars.rdf @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:exterms="http://www.example.org/terms/"> + <rdf:Description rdf:about="http://www.example.org/terms/Duck"> + <exterms:says>Duck says: "Quack!"</exterms:says> + </rdf:Description> + <rdf:Description rdf:about="http://www.example.org/terms/Cow"> + <exterms:says>Cow says: + 'Moo! \Moo!'</exterms:says> + </rdf:Description> diff --git a/tests/data/TextWithSpecialChars.ttl b/tests/data/TextWithSpecialChars.ttl new file mode 100644 index 0000000..6907ae7 --- /dev/null +++ b/tests/data/TextWithSpecialChars.ttl @@ -0,0 +1,8 @@ +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . +@prefix exterms: <http://www.example.org/terms/> . + +exterms:Duck exterms:says "Duck says: \"Quack!\"" . + +exterms:Cow exterms:says "Cow says:\n\r 'Moo! \\Moo!'" . + diff --git a/tests/phpunit/RdfWriterTestBase.php b/tests/phpunit/RdfWriterTestBase.php index 327e88b..1d8fcac 100644 --- a/tests/phpunit/RdfWriterTestBase.php +++ b/tests/phpunit/RdfWriterTestBase.php @@ -309,6 +309,16 @@ $this->assertOutputLines( 'NumberedBlankNode', $rdf ); } + public function testQuotesAndSpecials() { + $writer = $this->newWriter(); + $writer->prefix( 'exterms', 'http://www.example.org/terms/' ); + $writer->start(); + $writer->about('exterms', 'Duck')->say('exterms', 'says')->text('Duck says: "Quack!"'); + $writer->about('exterms', 'Cow')->say('exterms', 'says')->text("Cow says:\n\r 'Moo! \\Moo!'"); + $rdf = $writer->drain(); + $this->assertOutputLines( 'TextWithSpecialChars', $rdf ); + } + /** * @param string $datasetName * @param string[]|string $actual @@ -360,7 +370,6 @@ $this->assertEquals( $missing, $extra, $message ); } - //FIXME: test quoting/escapes! //FIXME: test non-ascii literals! //FIXME: test uerl-encoding //FIXME: test IRIs! -- To view, visit https://gerrit.wikimedia.org/r/332816 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9f9ed50e083542191c8eecfeff4a56920e34f0e5 Gerrit-PatchSet: 1 Gerrit-Project: purtle Gerrit-Branch: master Gerrit-Owner: Smalyshev <smalys...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits