Skip to content

Commit

Permalink
Merge pull request #2693 from cloudflare/yagiz/fix-btoa-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig authored Sep 11, 2024
2 parents 3f81cd6 + 544cf75 commit 6a236a1
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/workerd/api/global-scope.c++
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,13 @@ void ServiceWorkerGlobalScope::emitPromiseRejection(jsg::Lock& js,

jsg::JsString ServiceWorkerGlobalScope::btoa(jsg::Lock& js, jsg::JsValue data) {
auto str = data.toJsString(js);
auto strArray = str.toArray<kj::byte>(js);

// We could implement btoa() by accepting a kj::String, but then we'd have to check that it
// doesn't have any multibyte code points. Easier to perform that test using v8::String's
// ContainsOnlyOneByte() function.
JSG_REQUIRE(str.containsOnlyOneByte(), DOMInvalidCharacterError,
"btoa() can only operate on characters in the Latin1 (ISO/IEC 8859-1) range.");

auto strArray = str.toArray<kj::byte>(js);
auto expected_length = simdutf::base64_length_from_binary(strArray.size());
auto result = kj::heapArray<kj::byte>(expected_length);
auto written = simdutf::binary_to_base64(
Expand Down

0 comments on commit 6a236a1

Please sign in to comment.