diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2023-11-07 06:18:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 22:18:28 +0100 |
commit | 90189dd9974be01596ec776e63a4eceef1a036e0 (patch) | |
tree | 5ef3171dfc4181e1682d86ccd4daa5c874bc261a /ext/node/polyfills/util.ts | |
parent | 7eb34c7a36ac065d169e3645fc8a3da3e71431d7 (diff) |
fix(ext): use `String#toWellFormed` in ext/webidl and ext/node (#21054)
Fixes #18802
This PR adds `util.toUSVString` to node:util:
```js
import util from "node:util";
util.toUSVString("string\ud801"); // => "string\ufffd"
```
Diffstat (limited to 'ext/node/polyfills/util.ts')
-rw-r--r-- | ext/node/polyfills/util.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/ext/node/polyfills/util.ts b/ext/node/polyfills/util.ts index 1b611b1fd..2e25746ef 100644 --- a/ext/node/polyfills/util.ts +++ b/ext/node/polyfills/util.ts @@ -37,7 +37,9 @@ const { SafeSet, SetPrototypeAdd, SetPrototypeHas, + StringPrototypeIsWellFormed, StringPrototypePadStart, + StringPrototypeToWellFormed, } = primordials; export { @@ -187,6 +189,13 @@ export const TextDecoder = _TextDecoder; export type TextEncoder = import("./_utils.ts")._TextEncoder; export const TextEncoder = _TextEncoder; +export function toUSVString(str: string): string { + if (StringPrototypeIsWellFormed(str)) { + return str; + } + return StringPrototypeToWellFormed(str); +} + function pad(n: number) { return StringPrototypePadStart(NumberPrototypeToString(n), 2, "0"); } @@ -309,6 +318,7 @@ export default { stripVTControlCharacters, TextDecoder, TextEncoder, + toUSVString, log, debuglog, isDeepStrictEqual, |