Unquoted value in JSON response
Closed, ResolvedPublic

Assigned To
None
Priority
Normal
Author
bzimport
Subscribers
Catrope, wikibugs-l
Projects
Reference
bz11633
Description

Author: russblau

Description:
When using JSON format only, with redirects=redirects, if a page title happens to be an integer, the title is not quoted as a string in the response but is sent as an integer.

This occurs, for example, in the response to http://en.wikipedia.org/w/api.php?action=query&titles=-100&prop=info&redirects=redirects&format=jsonfm

Note that in the response, the title -100 is not quoted in the redirects
value --

"redirects": [

{
  "from": -100,
  "to": "100 BC"
}

],

However, in the XML response to http://en.wikipedia.org/w/api.php?action=query&titles=-100&prop=info&redirects=redirects, the title "-100" is quoted properly; also, in http://en.wikipedia.org/w/api.php?action=query&titles=-100&prop=info&format=jsonfm, where the redirect is not resolved, the title "-100" is quoted properly.


Version: unspecified
Severity: normal

bzimport added a project: MediaWiki-API.Via ConduitNov 21 2014, 9:58 PM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz11633.
bzimport created this task.Via LegacyOct 11 2007, 3:00 PM
brion added a comment.Via ConduitOct 15 2007, 7:56 PM

This is a side-effect of PHP's weak typing; something's overzealously converting the string-that-looks-like-an-int to an integer during processing.

The JSON formatter then, quite correctly, outputs a formatted integer rather than a string. (You can verify this by slipping in a var_dump() on the request data in ApiFormatJson::execute(); the -100 is listed as an int, not a string.)

brion added a comment.Via ConduitOct 15 2007, 8:01 PM

Note that while this means there's not a worry about security, one _can_ worry about it causing problems with use of the data in a more strongly-typed language, say Python, where ints and strings aren't freely interchangable.

bzimport added a comment.Via ConduitApr 5 2008, 6:35 PM

Bryan.TongMinh wrote:

Fixed in r32820. It appears that PHP automatically converts array keys that look like integers to integers. I knew that PHP was weakly types, but this weakly typed...

bzimport added a comment.Via ConduitFeb 26 2009, 9:20 PM

russblau wrote:

This has raised its ugly head again. In the response to the following query --

http://en.wikipedia.org/w/api.php?action=query&prop=categoryinfo&titles=Category:X1&format=jsonfm

three of the four numeric values are quoted, but one is not.

Catrope added a comment.Via ConduitFeb 26 2009, 9:31 PM

"pageid": 18413500,

				"ns": 14,
				"title": "Category:X1",
				"categoryinfo": {
					"size": "8",
					"pages": 8,
					"files": "0",
					"subcats": "0"

These are numbers that are really numbers that are not being quoted, while some others are. I agree that this is inconsistent, but it's not invalid. Reclosing as FIXED because the unquoted things really are integers, not strings that happen to look like them.

bzimport added a comment.Via ConduitFeb 26 2009, 9:53 PM

Bryan.TongMinh wrote:

Those numbers refer to amounts, which are always numbers and should be ints and not strings.

bzimport added a comment.Via ConduitFeb 27 2009, 2:21 PM

russblau wrote:

But then the quoted values shouldn't be quoted. The current output format makes no sense.

Catrope added a comment.Via ConduitFeb 27 2009, 4:04 PM

(In reply to comment #7)

But then the quoted values shouldn't be quoted. The current output format
makes no sense.

I've converted all numeric values I could find to integers in r47865.

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.