Skip to content
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

fix 9395 #14815

Merged
merged 1 commit into from
Oct 26, 2024
Merged

fix 9395 #14815

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bun.js/bindings/webcore/JSTextEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ static inline JSC::EncodedJSValue jsTextEncoderPrototypeFunction_encodeBody(JSC:
UNUSED_PARAM(throwScope);
UNUSED_PARAM(callFrame);
EnsureStillAliveScope argument0 = callFrame->argument(0);
if (argument0.value().isUndefined()) {
auto res = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->m_typedArrayUint8.get(lexicalGlobalObject), 0);
RELEASE_AND_RETURN(throwScope, JSValue::encode(res));
}
JSC::JSString* input = argument0.value().toStringOrNull(lexicalGlobalObject);
JSC::EncodedJSValue res;
String str;
Expand Down
6 changes: 6 additions & 0 deletions test/js/web/encoding/text-encoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ it("not enough space for replacement character", () => {
});

describe("TextEncoder", () => {
it("should handle undefined", () => {
const encoder = new TextEncoder();
expect(encoder.encode(undefined).length).toBe(0);
expect(encoder.encode(null).length).toBe(4);
expect(encoder.encode("").length).toBe(0);
});
it("should encode latin1 text with non-ascii latin1 characters", () => {
var text = "H©ell©o Wor©ld!";

Expand Down