iRail / hyperRail

The repo for the iRail.be webapp
https://iRail.be
Creative Commons Zero v1.0 Universal
47 stars 17 forks source link

Forward slashes shouldn't be escaped when returning data as JSON #278

Closed Bertware closed 6 years ago

Bertware commented 6 years ago

When requesting data in the json or json-ld format, URLs are escaped. This makes them invalid.

Actual output:

{
"@context":{
"delay":"http:\/\/semweb.mmlab.be\/ns\/rplod\/delay",
"platform":"http:\/\/semweb.mmlab.be\/ns\/rplod\/platform",
"scheduledDepartureTime":"http:\/\/semweb.mmlab.be\/ns\/rplod\/scheduledDepartureTime",
"headsign":"http:\/\/vocab.org\/transit\/terms\/headsign",
"routeLabel":"http:\/\/semweb.mmlab.be\/ns\/rplod\/routeLabel",
"stop":{"@id":"http:\/\/semweb.mmlab.be\/ns\/rplod\/stop","@type":"@id"}
},
"@graph":[
{
"@id":"https:\/\/irail.be\/stations\/nmbs\/008892007\/departures\/2018022218024dcc175d90fd67f8d8ecfff88eb8143b",
"delay":"480",
"platform":"12",
"canceled":"0",
"scheduledDepartureTime":"2018-02-22T18:02:00+01:00",
"stop":"https:\/\/irail.be\/stations\/NMBS\/008892007",
"headsign":"Knokke","routeLabel":"IC 2838"
},
 ... ]
}

Expected output:

For example http:\/\/semweb.mmlab.be\/ns\/rplod\/delay should be http://semweb.mmlab.be/ns/rplod/delay. This goes for all URLs.

Solution:

We should use the flag JSON_UNESCAPED_SLASHES when encoding json data. See also: https://stackoverflow.com/questions/10210338/json-encode-escaping-forward-slashes

pietercolpaert commented 6 years ago

Not a bug: doesn’t break anything and is spec compliant. Wouldn’t mind getting rid of the escapes though.