C. Scott Ananian has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/387661 )
Change subject: Fix bug in JSON-LD output when alternating values are specified.
......................................................................
Fix bug in JSON-LD output when alternating values are specified.
If an existing predicate is reopened to add new values, the simple
array cast could misinterpret an array-valued singleton.
Change-Id: I6c9ee4f824b9b7666334734878685d9ec61387ee
---
M src/JsonLdRdfWriter.php
M tests/data/AlternatingValues.jsonld
2 files changed, 23 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/61/387661/1
diff --git a/src/JsonLdRdfWriter.php b/src/JsonLdRdfWriter.php
index d2735a3..12055d7 100644
--- a/src/JsonLdRdfWriter.php
+++ b/src/JsonLdRdfWriter.php
@@ -332,7 +332,14 @@
$name = $this->compactify( $base, $local );
}
if ( isset( $this->predicates[$name] ) ) {
- $this->values = array_merge(
(array)$this->predicates[$name], $this->values );
+ $was = $this->predicates[$name];
+ // Wrap $was into a numeric indexed array if it isn't
already.
+ // Note that $was could have non-numeric indices, eg
+ // [ "@id" => "foo" ], in which was it still needs to
be wrapped.
+ if (!(is_array($was) && isset($was[0]))) {
+ $was = [ $was ];
+ }
+ $this->values = array_merge( $was, $this->values );
}
$cnt = count( $this->values );
diff --git a/tests/data/AlternatingValues.jsonld
b/tests/data/AlternatingValues.jsonld
index 3654234..ce7ed09 100644
--- a/tests/data/AlternatingValues.jsonld
+++ b/tests/data/AlternatingValues.jsonld
@@ -1,26 +1,30 @@
{
"@id": "wikibase:Dump",
- "owl:foo": {
- "@id": "owl:A",
- "0": {
+ "owl:foo": [
+ {
+ "@id": "owl:A"
+ },
+ {
"@id": "owl:B"
},
- "1": {
+ {
"@id": "owl:C"
}
- },
- "owl:bar": {
- "@type": "xsd:decimal",
- "@value": "5",
- "0": {
+ ],
+ "owl:bar": [
+ {
+ "@type": "xsd:decimal",
+ "@value": "5"
+ },
+ {
"@type": "xsd:decimal",
"@value": "6"
},
- "1": {
+ {
"@type": "xsd:decimal",
"@value": "7"
}
- },
+ ],
"@context": {
"wikibase": "http://wikiba.se/ontology-beta#",
"owl": "http://www.w3.org/2002/07/owl#",
--
To view, visit https://gerrit.wikimedia.org/r/387661
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c9ee4f824b9b7666334734878685d9ec61387ee
Gerrit-PatchSet: 1
Gerrit-Project: purtle
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits