You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the web page's argv string encoding a faithful round trip
Fixes scrutineer finding #2519.
In fiat-html/main.js, splitUnescapedSpaces and joinWithEscaping convert
between the "Input String" text box and the argv array passed to the
worker. The decoder used U+0000 and U+0001 as internal placeholders and
dropped empty strings, so `splitUnescapedSpaces(joinWithEscaping(a))` was
not `a` for arguments containing those characters or for empty arguments.
When the page was opened via a crafted `?argv=...&interactive` link,
`updateInputType` re-encoded the text box lossily while `parseAndRun`
synthesised from the original argv, so the visitor saw one command line
and ran another. With `&inputType=json` the text box was additionally
mangled by running the string decoder over JSON text.
Fix:
* Move the pair to a new file fiat-html/argv-string.js and reimplement the
decoder as a character-by-character parser with no placeholder
characters. `\ ` and `\\` keep their meaning; `\"` is a literal quote;
a bare `""` token is the empty argument (the only new syntax). Any other
backslash sequence is kept literally, as before. The encoder emits `""`
for empty arguments and escapes the quotes of an argument that is
literally `""`. The file is a classic browser script that also exports
the two functions when loaded under CommonJS, so it can be unit-tested.
* On load from a URL, decode ?argv=, ?stdin= and ?files= once and derive
both the form contents and the arguments handed to the worker from that
single decoded value. The Synthesize button likewise goes through one
`getInputArgs` helper. ?inputType= is now normalised to 'json' or
'string' instead of being interpolated into a CSS selector.
* Fix the permalink, which emitted `&inputType=&inputType=json` and so
never reopened in JSON view.
* Add fiat-html/tests/argv-roundtrip.test.js (node's built-in test
runner, no dependencies): hand-picked adversarial cases, 20000 random
arrays over an adversarial alphabet, agreement with the old decoder on
legacy input, and stability under string/JSON toggling. A small
workflow runs it on changes to fiat-html/.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Rbn2gww3MGhvrh52fNjpD
0 commit comments