Skip to content

io: preserve numeric string arguments when writing - #151

Open
flynn-eye wants to merge 1 commit into
Shopify:mainfrom
flynn-eye:codex/preserve-io-write-strings
Open

flynn-eye wants to merge 1 commit into
Shopify:mainfrom
flynn-eye:codex/preserve-io-write-strings

Conversation

@flynn-eye

Copy link
Copy Markdown

io.write("123 ") currently writes 123, and strings such as "001.20 " or "0x10 " are reformatted as numbers. The shared write helper calls ToNumber before checking whether an argument is already a string.

Use CheckString directly: string bytes are preserved, while actual numbers still use the existing numberToString conversion. Regression coverage exercises both io.write and file:write, including whitespace, leading zeros, hexadecimal/exponent strings, actual numbers, and the returned file handle.

Fixes #92.

Validation on Go 1.25.0, darwin/arm64:

  • Both new regression cases fail on the old helper and pass after the change.
  • go test -vet=off -race ./... passes with the lua-tests submodule initialized. Existing tests requiring luac skip because it is not installed; the existing architecture-dependent test also skips.
  • go vet -tests=false ./... passes.

Default test vet reports the pre-existing non-niladic ExampleFunction in doc_test.go; the same error was verified on pristine upstream 3f823f8.

Write strings as supplied instead of coercing them to numbers first. CheckString preserves their whitespace and representation while retaining the existing formatting for actual numbers. Cover io.write and file:write with output and return-value regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

io.write discards spaces after trailing numbers

1 participant