oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.23k stars 2.77k forks source link

`fileName` is `undefined` when creating an empty `File` object. #5254

Open Hanaasagi opened 1 year ago

Hanaasagi commented 1 year ago

What version of Bun is running?

1.0.1+a3166457d3122b6b86958c43dce47b86af0dc3e2

What platform is your computer?

Linux 6.5.2-arch1-1 x86_64 unknown

What steps can reproduce the bug?

const { File } = require("node:buffer");
const assert = require("node:assert");

{
  const file = new File([""], "file.txt");
  assert.strictEqual(file.name, "file.txt");
}

{
  const file = new File([], "file.txt");
  assert.strictEqual(file.name, "file.txt");
}

What is the expected behavior?

No assertion error

What do you see instead?

AssertionError: Expected values to be strictly equal:
+ actual - expected

+ undefined
- 'file.txt'
 code: "ERR_ASSERTION"

Additional information

No response

Hanaasagi commented 1 year ago

https://github.com/oven-sh/bun/blob/0404d09cc74d865c09a9c4fa965d078035d07027/src/bun.js/webcore/blob.zig#L1191-L1195

https://github.com/oven-sh/bun/blob/0404d09cc74d865c09a9c4fa965d078035d07027/src/bun.js/webcore/blob.zig#L3330-L3341

When the content is empty, the store variable remains null, which results in the filename not being assigned.

ChuckJonas commented 10 months ago

any update on this? It's a pain if you are trying to unit test with the File object