Skip to content

Preserve embedded NUL bytes in TEXT values#8

Open
sbking wants to merge 1 commit into
Effect-TS:mainfrom
sbking:fix/text-nul-round-trip
Open

Preserve embedded NUL bytes in TEXT values#8
sbking wants to merge 1 commit into
Effect-TS:mainfrom
sbking:fix/text-nul-round-trip

Conversation

@sbking

@sbking sbking commented Jul 16, 2026

Copy link
Copy Markdown

Summary

sqlite3_bind_text currently passes -1 as the byte length, and the Emscripten string return conversion used by column_text also treats NUL as a terminator. As a result, TEXT values containing embedded NUL bytes are truncated in both directions.

  • pass the encoded UTF-8 byte length to sqlite3_bind_text
  • decode the complete sqlite3_column_bytes range while retaining Emscripten's existing UTF-8 decoding behavior
  • add separate write-side and read-side regression tests, including preservation of a leading byte order mark

Testing

  • focused Chrome tests before the fix: both new assertions fail independently at the embedded NUL
  • focused Chrome tests after the fix: 7 passed, 0 failed
  • compatibility probes preserve SQL NULL for non-string low-level bind_text inputs, leading U+FEFF, and existing malformed UTF-8 decoding
  • prettier --check src/sqlite-api.js .changeset/fuzzy-spoons-smile.md
  • node --check test/api_statements.js

The repository's full api.test.js exceeded Web Test Runner's file-level finish timeout on both pristine main (120 seconds) and this branch (300 seconds), so I don't have a full-suite result for either tree.

References

Checklist

  • I grant to recipients of this Project distribution a perpetual,
    non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
    derivative works of, publicly display, sublicense, and distribute this
    Contribution and such derivative works.
  • I certify that I am legally entitled to grant this license, and that this
    Contribution contains no content requiring a license from any third party.

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