[openstreetmap/openstreetmap-website] old user preferences containing "%" break PUT on /api/0.6/user/preferences (Issue #4467)

Matija Nalis notifications at github.com
Tue Jan 9 22:12:39 UTC 2024


### URL

https://www.openstreetmap.org/api/0.6/user/preferences

### How to reproduce the issue?

- find an old user who has lone percent sign (`%`) somewhere in preferences. For [me](https://www.openstreetmap.org/user/Matija%20Nalis), it was some preferences put by [Merkaartor](https://wiki.openstreetmap.org/wiki/Merkaartor) app some number of years ago, in the following format:

 ```
 <preference k="MerkaartorTmsServer003" v="OSM Mapnik;tile.openstreetmap.org;/%1/%2/%3.png;256;0;17"/>
 ```

  (you need to use an old user, as it is impossible to recreate preferences with lone `%` even for testing)

- you do `GET /api/0.6/user/preferences` and read those preferences just fine
- however, when you try to `PUT /api/0.6/user/preferences` them back again (with some or no changes), you get `400 Bad Request` HTTP error (without any more informative `error` header/text (like one might get for trying to e.g. upload duplicate key or other errors).


That is quite unfortunate, at it means (among other things) that people who have used Merkaartor (or other apps which might use `%` in preferences) in the past are (among other things, but as an example) [unable to save overpass-turbo queries to OSM](https://github.com/tyrasd/overpass-turbo/issues/666#issuecomment-1883698962) any more (note that overpass-turbo had another unrelated but there, but fixing it only fixed the issue for some people, not all).

### Screenshot(s) or anything else?

Possible solutions (from more preferred to less preferred)

- Allow lone `%` in the preferences again, as they were allowed in the past (i.e. undo the regression that introduced this change). That would fix this, and likely related issue: https://github.com/openstreetmap/openstreetmap-website/issues/4001. The advantage is that nothing else needs to be changed and everything starts working automagically.
- replace lone `%` (i.e. not followed by 2 hexadecimal characters) in the OSM preferences database by [percent-encoded](https://en.wikipedia.org/wiki/Percent-encoding) `%25`, as it seems to be what OSM API expects nowdays (at least the error is gone and preference is uploaded when one does that). The disadvantage is that any app which uses such values need to be informed that they need to parse percent-encoded values now. 
 E.g. example above would become:
 ```
 <preference k="MerkaartorTmsServer003" v="OSM Mapnik;tile.openstreetmap.org;/%251/%252/%253.png;256;0;17"/>
 ```
- delete (after backing up) all keys in preferences database that contain lone `%`. That would at least allow preferences to be changed / saved again and avoid user frustration (but original data would be lost -- hopefully it is only old historical preferences of little value).
- at least [document](https://wiki.openstreetmap.org/wiki/API_v0.6#Preferences_of_the_logged-in_user:_GET_/api/0.6/user/preferences) this `%` behaviour (and possible remedy for affected users) 


-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/4467
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/4467 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240109/6616f04a/attachment.htm>


More information about the rails-dev mailing list