Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/202913
Change subject: T95461: fix URL escaping
......................................................................
T95461: fix URL escaping
Change-Id: I59950250f0635cc0f5fc764f31584ebf83593f06
---
M purtle/src/N3Quoter.php
M purtle/src/N3RdfWriterBase.php
M purtle/src/TurtleRdfWriter.php
M repo/tests/phpunit/data/rdf/Q4.json
M repo/tests/phpunit/data/rdf/Q4_all_statements.nt
M repo/tests/phpunit/data/rdf/Q4_claims.nt
M repo/tests/phpunit/data/rdf/Q4_props.nt
M repo/tests/phpunit/data/rdf/Q4_resolved.nt
M repo/tests/phpunit/data/rdf/Q4_truthy_statements.nt
M repo/tests/phpunit/data/rdf/Q4_values.nt
10 files changed, 15 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/13/202913/1
diff --git a/purtle/src/N3Quoter.php b/purtle/src/N3Quoter.php
index 35f3a76..6b886b0 100644
--- a/purtle/src/N3Quoter.php
+++ b/purtle/src/N3Quoter.php
@@ -30,6 +30,7 @@
'"' => '%22',
'<' => '%3C',
'>' => '%3E',
+ '\\' => '%5C',
) );
}
diff --git a/purtle/src/N3RdfWriterBase.php b/purtle/src/N3RdfWriterBase.php
index 575844e..ea405d7 100644
--- a/purtle/src/N3RdfWriterBase.php
+++ b/purtle/src/N3RdfWriterBase.php
@@ -17,29 +17,10 @@
*/
protected $quoter;
- /**
- * @var bool
- */
- private $trustIRIs = true;
-
public function __construct( $role = parent::DOCUMENT_ROLE,
BNodeLabeler $labeler = null, N3Quoter $quoter = null ) {
parent::__construct( $role, $labeler );
$this->quoter = $quoter ?: new N3Quoter();
- }
-
- /**
- * @return bool
- */
- public function getTrustIRIs() {
- return $this->trustIRIs;
- }
-
- /**
- * @param bool $trustIRIs
- */
- public function setTrustIRIs( $trustIRIs ) {
- $this->trustIRIs = $trustIRIs;
}
protected function writeRef( $base, $local = null ) {
@@ -62,7 +43,7 @@
$this->write( $shorthand );
}
- protected function writeIRI( $iri ) {
+ protected function writeIRI( $iri, $trustIRI = false ) {
// if ( $iri === null || $iri === '' ) {
// throw new InvalidArgumentException( '$iri must not be
empty' );
// }
@@ -70,7 +51,7 @@
// if ( $iri[0] === '_' || $iri[0] === ':' || $iri[0] === '/' ||
$iri[0] === '#' ) {
// throw new InvalidArgumentException( '$iri must be an
absolute iri: ' . $iri );
// }
- if ( !$this->trustIRIs ) {
+ if ( !$trustIRI ) {
$iri = $this->quoter->escapeIRI( $iri );
}
$this->write( "<$iri>" );
diff --git a/purtle/src/TurtleRdfWriter.php b/purtle/src/TurtleRdfWriter.php
index 5fbdc45..0001ec2 100644
--- a/purtle/src/TurtleRdfWriter.php
+++ b/purtle/src/TurtleRdfWriter.php
@@ -40,7 +40,8 @@
if( $local !== null ) {
$this->write( "$base:$local" );
} else {
- $this->writeIRI( $base );
+ // We trust that subject IRIs are clean
+ $this->writeIRI( $base, 'trust' );
}
}
@@ -52,7 +53,8 @@
if( $local !== null ) {
$this->write( "$base:$local" );
} else {
- $this->writeIRI( $base );
+ // We trust that predicate IRIs are clean
+ $this->writeIRI( $base, 'trust' );
}
}
diff --git a/repo/tests/phpunit/data/rdf/Q4.json
b/repo/tests/phpunit/data/rdf/Q4.json
index 0b70c4a..84e5229 100644
--- a/repo/tests/phpunit/data/rdf/Q4.json
+++ b/repo/tests/phpunit/data/rdf/Q4.json
@@ -197,7 +197,7 @@
"property": "P9",
"datatype": "url",
"datavalue": {
- "value": "http:\/\/url.acme.test\/",
+ "value":
"http:\/\/url.acme.test\\badurl?chars=\\привет< >\"",
"type": "string"
}
},
diff --git a/repo/tests/phpunit/data/rdf/Q4_all_statements.nt
b/repo/tests/phpunit/data/rdf/Q4_all_statements.nt
index e9ae115..86e1e8c 100644
--- a/repo/tests/phpunit/data/rdf/Q4_all_statements.nt
+++ b/repo/tests/phpunit/data/rdf/Q4_all_statements.nt
@@ -53,7 +53,7 @@
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
-<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9> <http://url.acme.test/> .
+<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
diff --git a/repo/tests/phpunit/data/rdf/Q4_claims.nt
b/repo/tests/phpunit/data/rdf/Q4_claims.nt
index 942bd20..cb54274 100644
--- a/repo/tests/phpunit/data/rdf/Q4_claims.nt
+++ b/repo/tests/phpunit/data/rdf/Q4_claims.nt
@@ -19,7 +19,7 @@
<http://acme.test/Q4> <http://acme.test/assert/P6>
"+19.768000000000000682121026329696178436279296875"^^<http://www.w3.org/2001/XMLSchema#decimal>
.
<http://acme.test/Q4> <http://acme.test/assert/P7> "simplestring" .
<http://acme.test/Q4> <http://acme.test/assert/P8>
"-0200-01-01T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
-<http://acme.test/Q4> <http://acme.test/assert/P9> <http://url.acme.test/> .
+<http://acme.test/Q4> <http://acme.test/assert/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/Q4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Item> .
<http://acme.test/statement/TEST-Statement-2-423614cd831ed4e8da1138c9229cb65cf96f9366>
<http://acme.test/value/P2> <http://acme.test/Q42> .
<http://acme.test/statement/TEST-Statement-2-423614cd831ed4e8da1138c9229cb65cf96f9366>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
@@ -66,7 +66,7 @@
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
-<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9> <http://url.acme.test/> .
+<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
diff --git a/repo/tests/phpunit/data/rdf/Q4_props.nt
b/repo/tests/phpunit/data/rdf/Q4_props.nt
index ceca7a3..164777a 100644
--- a/repo/tests/phpunit/data/rdf/Q4_props.nt
+++ b/repo/tests/phpunit/data/rdf/Q4_props.nt
@@ -53,7 +53,7 @@
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
-<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9> <http://url.acme.test/> .
+<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
diff --git a/repo/tests/phpunit/data/rdf/Q4_resolved.nt
b/repo/tests/phpunit/data/rdf/Q4_resolved.nt
index 734f503..fafd1cf 100644
--- a/repo/tests/phpunit/data/rdf/Q4_resolved.nt
+++ b/repo/tests/phpunit/data/rdf/Q4_resolved.nt
@@ -7,7 +7,7 @@
<http://acme.test/Q4> <http://acme.test/assert/P6>
"+19.768000000000000682121026329696178436279296875"^^<http://www.w3.org/2001/XMLSchema#decimal>
.
<http://acme.test/Q4> <http://acme.test/assert/P7> "simplestring" .
<http://acme.test/Q4> <http://acme.test/assert/P8>
"-0200-01-01T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
-<http://acme.test/Q4> <http://acme.test/assert/P9> <http://url.acme.test/> .
+<http://acme.test/Q4> <http://acme.test/assert/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/Q4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Item> .
<http://data.acme.test/Q4> <http://schema.org/about> <http://acme.test/Q4> .
<http://data.acme.test/Q4> <http://schema.org/dateModified>
"2013-10-04T03:31:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
diff --git a/repo/tests/phpunit/data/rdf/Q4_truthy_statements.nt
b/repo/tests/phpunit/data/rdf/Q4_truthy_statements.nt
index 030de15..be3150f 100644
--- a/repo/tests/phpunit/data/rdf/Q4_truthy_statements.nt
+++ b/repo/tests/phpunit/data/rdf/Q4_truthy_statements.nt
@@ -7,7 +7,7 @@
<http://acme.test/Q4> <http://acme.test/assert/P6>
"+19.768000000000000682121026329696178436279296875"^^<http://www.w3.org/2001/XMLSchema#decimal>
.
<http://acme.test/Q4> <http://acme.test/assert/P7> "simplestring" .
<http://acme.test/Q4> <http://acme.test/assert/P8>
"-0200-01-01T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
-<http://acme.test/Q4> <http://acme.test/assert/P9> <http://url.acme.test/> .
+<http://acme.test/Q4> <http://acme.test/assert/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/Q4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Item> .
<http://data.acme.test/Q4> <http://schema.org/about> <http://acme.test/Q4> .
<http://data.acme.test/Q4> <http://schema.org/dateModified>
"2013-10-04T03:31:05Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
diff --git a/repo/tests/phpunit/data/rdf/Q4_values.nt
b/repo/tests/phpunit/data/rdf/Q4_values.nt
index 41f6355..93d851c 100644
--- a/repo/tests/phpunit/data/rdf/Q4_values.nt
+++ b/repo/tests/phpunit/data/rdf/Q4_values.nt
@@ -56,7 +56,7 @@
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-8-5dd0f6624a7545401bc306a068ac1bbe8148bfac>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
-<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9> <http://url.acme.test/> .
+<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://acme.test/value/P9>
<http://url.acme.test%5Cbadurl?chars=%5Cпривет%3C%20%3E%22> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.wikidata.org/ontology-0.0.1#Statement> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#NormalRank> .
<http://acme.test/statement/TEST-Statement-9-2669d541dfd2d6cc0105927bff02bbe0eec0e921>
<http://www.wikidata.org/ontology-0.0.1#rank>
<http://www.wikidata.org/ontology-0.0.1#BestRank> .
--
To view, visit https://gerrit.wikimedia.org/r/202913
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I59950250f0635cc0f5fc764f31584ebf83593f06
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits