Skip to content

fix: calculate encoded lengths from view byte lengths - #214

Open
bensynapse wants to merge 1 commit into
webtorrent:masterfrom
bensynapse:fix-view-encoding-length
Open

bensynapse wants to merge 1 commit into
webtorrent:masterfrom
bensynapse:fix-view-encoding-length

Conversation

@bensynapse

Copy link
Copy Markdown

I run Live Tennis API.

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[X] Bug fix
[ ] New feature
[ ] Other, please explain:

What changes did you make? (Give an overview)

encodingLength() uses the view's byteLength directly. A three byte view at offset 20 previously reported -13 encoded bytes. It now reports 5, matching encode().

The tests cover typed arrays, DataView and Buffer slices, including empty views and nested containers. A preallocation test reproduces the resulting RangeError before the fix.

Which issue (if any) does this pull request address?

No existing issue.

Is there anything you'd like reviewers to focus on?

A view's byteLength already excludes bytes before its offset.

node node_modules/tape/bin/tape test/encoding-length.test.js passes all 39 assertions on Node 12.22.12 and 22.23.2. Standard passes on both versions.

npm test stops in decode.dictionary with a TextDecoder argument error on both versions. The same failure reproduces on unchanged master with uint8-util 2.3.2.

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