Skip to content

Keep the case of short flags in PNG filenames - #1317

Open
farisbasha wants to merge 1 commit into
chubin:masterfrom
farisbasha:png-filename-flag-case
Open

farisbasha wants to merge 1 commit into
chubin:masterfrom
farisbasha:png-filename-flag-case

Conversation

@farisbasha

Copy link
Copy Markdown

ParseOptionsInFilename lowercases the whole PNG filename before it splits out the options. Short flags are case-sensitive, so the uppercase ones change meaning or make the request fail. The function's own doc comment says Rome_0pq_lang=it_T.png gives no-terminal=true, but today the T turns into t (transparency).

Repro on the live site:

curl -s -o /dev/null -w '%{http_code}\n' https://wttr.in/Paris_0pq.png    # 200
curl -s https://wttr.in/Paris_0pqQ.png
# failed to parse converted PNG query: ERR002: option has multiple values: q: [ ] (query was: 0=&p=&q=&q=)
curl -s -o /dev/null -w '%{http_code}\n' https://wttr.in/Paris_F.png      # 500
curl -s -o /dev/null -w '%{http_code}\n' https://wttr.in/Paris_I.png      # 500
filename part now expected
Q no-caption (q) no-city
T transparency=150 (t) no-terminal
M metric, wind not in m/s metric, wind in m/s
F, I, A unknown option: f / i / a, HTTP 500 no-follow-line / inverted colors / force-ansi

The Python parse_wttrin_png_name (removed in 168c304) kept the case of these parts, and the query-string form (?0pqQ) still works.

Fix: strip the .png/.PNG suffix without lowercasing the rest. The location, the dimension parts and the key=value parts are still lowercased, so Oymyakon, 300X and LANG=DE behave as before. Only the short-flag bundles keep their case.

Tests (Go 1.27 on Linux, after bash build.sh assets):

  • New TestCaseSensitiveFlagsInFilename. It checks ParseOptionsInFilename with .png and .PNG names, and a full Parse of a /Oymyakon_0pqQ_T_F.png request. It fails before this change ("option has multiple values: q") and passes after.
  • go test ./... and go vet ./internal/query/ pass.

This PR was prepared with AI assistance (Claude).

ParseOptionsInFilename lowercased the whole PNG filename before
splitting out the options, so case-sensitive short flags changed
meaning: Q (no-city) became q (no-caption), T (no-terminal) became
t (transparency), M lost m/s wind, and F, I and A were rejected as
unknown options. Paris_0pqQ.png failed with "option has multiple
values: q". The Python parse_wttrin_png_name kept their case.

Keep the case of the flag parts and lowercase only the location,
dimensions and key=value options, as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant