Page MenuHomePhabricator

Wikibase doesn’t validate formatter options, can crash with different TypeErrors
Open, Needs TriagePublic

Description

The wbformatvalue API has an options parameter that allows users to specify the FormatterOptions that will be used to format the value, as JSON. Several of Wikibase’s value formatters don’t really validate these options, so if an API user puts garbage in them, they can provoke various TypeErrors, For example, LatLongFormatter has options to customize the strings used for N/E/S/W, °/'/", set the format to float/dms/dm/dd and determine the floating point precision, where to put spacing, whether to use -1° or 1° S, and what the separator between latitude and longitude is. (Don’t ask me why this class is so amazingly configurable.) By setting the “north” option to an int instead, we get a type error.

api.php?action=wbformatvalue&format=json&generate=text%2Fplain&datavalue=%7B%0A%20%20%22value%22%3A%20%7B%0A%20%20%20%20%22latitude%22%3A%2027.988055555556%2C%0A%20%20%20%20%22longitude%22%3A%2086.925277777778%2C%0A%20%20%20%20%22altitude%22%3A%20null%2C%0A%20%20%20%20%22precision%22%3A%200.00027777777777778%2C%0A%20%20%20%20%22globe%22%3A%20%22http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ2%22%0A%20%20%7D%2C%0A%20%20%22type%22%3A%20%22globecoordinate%22%0A%7D%0A&options=%7B%22north%22%3A%201%7D&formatversion=2

datavalue={
  "value": {
    "latitude": 27.988055555556,
    "longitude": 86.925277777778,
    "altitude": null,
    "precision": 0.00027777777777778,
    "globe": "http://www.wikidata.org/entity/Q2"
  },
  "type": "globecoordinate"
}

options={"north": 1}

Exception caught: DataValues\\Geo\\Formatters\\LatLongFormatter::makeDirectionalIfNeeded(): Argument #2 ($positiveSymbol) must be of type string, int given