summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal_binding
diff options
context:
space:
mode:
authorChen Su <ghosind@gmail.com>2023-09-27 21:54:19 +0800
committerGitHub <noreply@github.com>2023-09-27 07:54:19 -0600
commit507f24c4746e24ea60dcebdffacd0b66e3d4bfc1 (patch)
tree710dbba8131625de018c506b8b9927621d1e9702 /ext/node/polyfills/internal_binding
parentaef56f3d70f3c898d7c99b74ad72cc08a16e5780 (diff)
fix(ext/node): fix TypeError in Buffer.from with base64url encoding. (#20705)
For the following example, if I set the encoding to `base64url`, it'll throw an unexpected TypeError: ```ts import { Buffer } from "node:buffer"; Buffer.from("IntcImhlbGxvXCI6XCJoZGQvZStpXCJ9Ig", "base64url").toString(); // error: Uncaught TypeError: src.subarray is not a function // const buf = Buffer.from( // ^ // at blitBuffer (ext:deno_node/internal/buffer.mjs:1779:15) // at Uint8Array.base64urlWrite (ext:deno_node/internal/buffer.mjs:691:10) // at Object.write (ext:deno_node/internal/buffer.mjs:2195:11) // at Uint8Array.write (ext:deno_node/internal/buffer.mjs:794:14) // at fromString (ext:deno_node/internal/buffer.mjs:214:22) // at _from (ext:deno_node/internal/buffer.mjs:119:12) // at Function.from (ext:deno_node/internal/buffer.mjs:157:10) // at file:///Users/foodieats/temp/buffer1.ts:3:20 ``` The error caused by `base64urlWrite` function, it should call `forgivingBase64UrlDecode` not `forgivingBase64UrlEncode` Also fixed #20563 .
Diffstat (limited to 'ext/node/polyfills/internal_binding')
-rw-r--r--ext/node/polyfills/internal_binding/_utils.ts4
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/node/polyfills/internal_binding/_utils.ts b/ext/node/polyfills/internal_binding/_utils.ts
index ab174608b..00993732f 100644
--- a/ext/node/polyfills/internal_binding/_utils.ts
+++ b/ext/node/polyfills/internal_binding/_utils.ts
@@ -5,7 +5,7 @@
import {
forgivingBase64Decode,
- forgivingBase64UrlEncode,
+ forgivingBase64UrlDecode,
} from "ext:deno_web/00_infra.js";
export function asciiToBytes(str: string) {
@@ -51,7 +51,7 @@ function base64clean(str: string) {
export function base64UrlToBytes(str: string) {
str = base64clean(str);
str = str.replaceAll("+", "-").replaceAll("/", "_");
- return forgivingBase64UrlEncode(str);
+ return forgivingBase64UrlDecode(str);
}
export function hexToBytes(str: string) {