Skip to content

Fix a nasty bug with typed subarrays #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KTibow
Copy link

@KTibow KTibow commented Jun 30, 2025

If you have a typed subarray for whatever reason, like using pbf's readBytes, devalue currently stringifies the whole buffer as shown in this example:

import { parse, stringify } from "npm:devalue";

const buffer = new ArrayBuffer(100);
const view = new Uint8Array(buffer);
const subarray = view.subarray(0, 10);

console.log(subarray.length); // 10
console.log(parse(stringify(subarray)).length); // Incorrectly 100

This fixes that by calling .slice() first.

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