Skip to content

Javascript fix issues, unit tests, adding CI#29

Merged
stephenberry merged 2 commits into
mainfrom
js-improvements
Dec 11, 2025
Merged

Javascript fix issues, unit tests, adding CI#29
stephenberry merged 2 commits into
mainfrom
js-improvements

Conversation

@stephenberry
Copy link
Copy Markdown
Member

@stephenberry stephenberry commented Dec 11, 2025

Fix JavaScript library bugs and add test suite

Summary

This PR fixes two reported bugs in the JavaScript BEVE library and adds a comprehensive test suite with CI integration.

Changes

Bug Fixes

Issue #9: String parsing fails for strings >= 64 characters

Root cause: Three bugs were identified:

  1. String length encoded as character count instead of byte count (beve.js)

    • The code used string.length (character count) instead of UTF-8 byte count
    • This violated the BEVE spec which requires byte count for string SIZE
    • Fixed by encoding to UTF-8 first: new TextEncoder().encode(value).length
  2. read_compressed() read extra bytes for multi-byte formats (beve.js)

    • After reading the header byte to determine config, the code read the full 2/4/8 bytes again
    • The header byte is part of the compressed value, so this read 1 extra byte
    • Fixed by reading from the current cursor position without pre-incrementing
  3. Big-endian byte order in read_compressed() (beve_file.js)

    • BEVE specifies little-endian, but the code used big-endian bit shifting
    • Fixed by using proper little-endian reading

Issue #7: TypeError for null/undefined values

Root cause: The write_value function had no handling for null or undefined.

Fix: Added handling that matches JSON.stringify behavior:

  • null → encodes as BEVE null (type 0, is_bool=0)
  • undefined at top level → encodes as null
  • undefined in arrays → encodes as null
  • undefined in object values → property is omitted
  • Empty objects {} → now supported (previously threw)

Also fixed typed array detection to check all elements are numbers, not just the first.

Test Suite

Added Jest test framework with 80 tests covering:

Category Tests Description
Primitive Types 11 Booleans, integers, floats
Null/Undefined (Issue #7) 10 null, undefined in various contexts
String Handling 5 Basic string operations
String Boundaries (Issue #9) 10 63, 64, 65, 127, 16383, 16384 char strings
UTF-8 Multi-byte 7 Emoji, Chinese characters, mixed content
Objects 7 Simple, nested, empty, deeply nested
Object Key Boundaries 5 Long keys, UTF-8 keys
Long String Values 4 Issue #9 exact scenarios
Typed Arrays 4 Integer and float arrays
Untyped Arrays 4 Mixed types, nested
Edge Cases 5 Empty strings, null chars, surrogate pairs
Compatibility 6 Reading existing .beve example files
Regression 3 Issue #9 specific regression tests

CI Integration

Added GitHub Actions workflow (.github/workflows/test.yml) that:

  • Runs on push to main and on pull requests
  • Sets up Node.js 20
  • Runs the test suite

Files Changed

File Change
javascript/beve.js Bug fixes for issues #7 and #9
javascript/beve_file.js Bug fix for issue #9 (byte order)
javascript/beve.test.js New: comprehensive test suite
javascript/package.json New: npm package config with Jest
javascript/package-lock.json New: dependency lock file
.github/workflows/test.yml New: CI workflow
.gitignore Updated: ignore node_modules, allow package.json

Testing

cd javascript
npm install
npm test

All 80 tests pass.

Compatibility

  • No breaking changes to the public API
  • Encoded data from the fixed library can be read by other BEVE implementations
  • Existing .beve files continue to work (verified by compatibility tests)

@stephenberry stephenberry linked an issue Dec 11, 2025 that may be closed by this pull request
@stephenberry stephenberry linked an issue Dec 11, 2025 that may be closed by this pull request
@stephenberry stephenberry merged commit 767b1e3 into main Dec 11, 2025
1 check passed
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.

does not parse correctly after compressing large string size TypeError: Cannot convert undefined or null to object

1 participant