openstreetmap / openstreetmap-website

The Rails application that powers OpenStreetMap
https://www.openstreetmap.org/
GNU General Public License v2.0
2.16k stars 908 forks source link

Wrong display of tag values #4036

Closed mueschel closed 9 months ago

mueschel commented 1 year ago

Hi,

URL

https://www.openstreetmap.org/way/1101344113

Description

I noticed a strange discrepancy between a tag displayed on the website and its actual value in the database: I found it on way 1101344113, version 15.

On the website, the value of the key destination:colour:back:lanes:forward is shown as |white. The actual value in the database (as retrieved using Overpass and the API) is |white;.

Why is the semicolon missing in the display on the website?

gravitystorm commented 1 year ago

Due to the way that we process semicolons as delineators for multiple values, we currently discard trailing semicolons. This isn't intentional.

The value of every tag shown is processed to some extent, the value |white; is handled here:

https://github.com/openstreetmap/openstreetmap-website/blob/933292167a42ffbd51d5054f640e33620456161d/app/helpers/browse_tags_helper.rb#L39

In Ruby, String#split discards any trailing null values, but this can be overridden by a passing a negative limit (i.e. to return all parts).

irb(main):006:0> "|white;".split(";")
=> ["white"]
irb(main):007:0> "|white;".split(";", -1)
=> ["white", ""]

To fix this, that line needs changing, and some tests need writing to cover this example too.