Last modified: 2012-07-05 19:51:03 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T25946, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 23946 - JSON output from #ask does not escape "
JSON output from #ask does not escape "
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Markus Krötzsch
:
Depends on: 37418
Blocks:
  Show dependency treegraph
 
Reported: 2010-06-13 19:29 UTC by MK
Modified: 2012-07-05 19:51 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description MK 2010-06-13 19:29:01 UTC
Here's an example:

                {
                        "label": "Follow",

                        "shortdesc": "Implements "tail -f" functionality",

                        "uri" : "http://localhost/wiki/index.php?title=Follow",
                }

This is output from {{#ask[[someprop::someval]] | ?shortdesc=}}.  "Shortdesc" is of type String, so it should be expected to possibly contain quotes, as above.  However, this short circuits the decoding of the JSON -- eg, php's own decode_json will fail here and return NULL.  Parsing the reply to escape the quotes -- so: "Implements \"tail -f\" functionality" corrects the issue and decode_json works properly. Obviously, SMW should not be providing bad JSON data!
Comment 1 Matt Voysey 2011-04-07 16:01:29 UTC
The problem is not limited to property values. Valid MediaWiki article names containing quotes (such as "Weird Al" Yankovic) also create invalid JSON output:

{
  "label" : ""Weird Al" Yankovic",
  "uri" : "http://localhost/mediawiki/index.php?title=""Weird Al" Yankovic",
  ...
}

I fixed this particular case by hacking SMW_QP_JSONlink.php to do a str_replace:

valuestack[] = '"uri" : "' . $wgServer . $wgScriptPath . '/index.php?title=' . str_replace("\"", "\\\"", $prefixedtext) . '"';

As a secondary issue: Notice also that the "label" is getting htmlescaped, which is probably not what is actually wanted in JSON output? Changing this now though would break existing users, so I guess we're stuck with that one?
Comment 2 Mike Linksvayer 2011-05-19 23:56:47 UTC
Fix by Matt Voysey appears to work, see http://code.creativecommons.org/issues/issue847 for more.
Comment 3 MWJames 2012-07-05 19:51:03 UTC
The string escape problem is solved with the new JSON export but please be aware that the JSON structure has changed beginning with (bug 37418).

[1] http://www.semantic-mediawiki.org/wiki/Help:JSON_format#Structure

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links