Offroaders123 / NBTify

A library to read and write NBT files on the web!
http://npm.im/nbtify
MIT License
42 stars 5 forks source link

Root Name String Validation #48

Closed Offroaders123 closed 2 months ago

Offroaders123 commented 2 months ago

When passing a string value to NBT.read(), the function should check that it's parsed root name value equals that of the string parsed in.

If one doesn't know what that string is when reading, they can set it to true, and it will only validate whether there is a root name, rather than what it actually is.

Right now, the unexpected handling is that passing a string for ReadOptions["rootName"] is no different than passing true.

import { read } from "nbtify";

declare const data: Uint8Array;

// detect the status of the root name for us
await read(data);
await read(data, {});
await read(data, { rootName: undefined });

// assert that it should have a root name
await read(data, { rootName: true });

// assert that it should not have a root name
await read(data, { rootName: false });

// assert that the root name should specifically be "hello world" (expected behavior, this needs to be added)
await read(data, { rootName: "hello world" });