Skip to content

Accept bare t flag as transparency=150 - #1307

Merged
chubin merged 1 commit into
chubin:masterfrom
mmporong:fix-png-t-transparency
Nov 24, 2026
Merged

chubin merged 1 commit into
chubin:masterfrom
mmporong:fix-png-t-transparency

Conversation

@mmporong

Copy link
Copy Markdown
Contributor

Fixes #1263

Problem

:help and the README document t as a bare PNG flag meaning transparency=150, and the README's PNG example uses it (Oymyakon_tqp0.png). The parser rejects it:

failed to parse converted PNG query: ERR007: option requires a value: t (query was: 0=&p=&q=&t=)

transparency is an integer option in options.yaml, and validateAndSetFlag returns ErrValueRequired for every non-boolean option used as a flag. The query string form (/Oymyakon.png?t) fails with the same ERR007, because both paths go through ParseQueryString.

Change

  • internal/query/parse.go: when a non-boolean option is used as a bare flag, look it up in a small shortFlagValues table (transparency: "150") instead of failing. If the same query also has an explicit transparency=N, the explicit value wins regardless of map iteration order.
  • t is the only short option in options.yaml that is not boolean, so no other flag changes behavior.
  • internal/query/queryparser_test.go: TestTransparencyFlag covers Oymyakon_tqp0.png, Oymyakon_t.png, Oymyakon_t=200.png, Oymyakon_t_transparency=100.png (via ParseOptionsInFilename) and ?t, ?tqp0, ?t&transparency=100, ?transparency=100&t (via Parse, repeated 20 times because parameter order comes from a map).

Testing

Run in the golang:1.25 image, with internal/assets/embed populated the way build.sh assets does:

  • go test ./internal/query/...: TestTransparencyFlag fails on master with the ERR007 above and passes with this change. TestWeatherUnits passes on both. With the "explicit value wins" check removed, the test fails (3 of 3 runs).
  • go test ./...: all packages pass.
  • go vet ./internal/query/: no findings. gofmt -d shows nothing for parse.go; for queryparser_test.go it shows only the existing import block.
  • I also compared ParseQueryString on master and this branch over 50,032 query strings (fixed edge cases plus random strings over the short-flag alphabet and separators), treating all error codes as one outcome. 1,355 inputs that were errors on master now parse; every one contains t, and each result includes transparency=150 or the explicit value. No input that parsed on master changed. The other differences are only which error code is reported first (for example tz: ERR007 before, ERR003 now).

Not in this PR

The second point in this comment (the PNG has no alpha even when the value parses) is a separate problem. With this change, Oymyakon_tqp0.png no longer fails, but in strictQueryParser.Parse the options from the file name are merged with mergo.Merge(opts, *filenameOpts), which only fills zero fields. ApplyParsedMap has already set opts.Transparency = 255 (and opts.Lang = "en") for the query-string side, so the file-name value is dropped. Checked with Parse:

URL Transparency Lang
/Oymyakon_t=100.png (master and this branch) 255 en
/Oymyakon_lang=fr.png (master and this branch) 255 en
/Oymyakon_tqp0.png (this branch) 255 en
/Oymyakon.png?t (this branch) 150 en

So after Parse, ?t gives Transparency 150, while the file-name form parses but still reaches the renderer with 255 (opaque) until the merge is fixed. This PR fixes the error in the issue title; you may want to keep tracking the file-name transparency separately. I kept the merge out of this PR because fixing it changes the precedence of every file-name option.

Related behavior this PR leaves unchanged:

  • transparency=0 is turned into 255 (ApplyParsedMap and ansitopng treat 0 as unset), so fully transparent output is not reachable.
  • ParseOptionsInFilename lowercases the whole file name, so _T (no-terminal) in a file name becomes t. On master that was ERR007; with this change it parses as transparency=150. The docstring example Rome_0pq_lang=it_T.png -> no-terminal=true was already not what happens.
  • A flag repeated in a file name (Oymyakon_tqp0_t.png, Oymyakon_qq.png) is still ERR002, because each character is added to the query separately.

The :help page and README document the short option t as a bare flag
meaning transparency=150 (e.g. Oymyakon_tqp0.png), but the query parser
rejected it with ERR007 because transparency is an integer option.

Give t its documented value when it is used as a flag, so it parses in
the query string and in PNG file names. An explicit transparency=N
still wins.
@chubin
chubin merged commit b5a3f3d into chubin:master Nov 24, 2026
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.

"t" option giving error for PNG format

2 participants