From 49ccfdd696060cd07d8e391bea7d086892ea0ede Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Wed, 5 Jan 2022 00:42:30 +0100 Subject: [PATCH] refactor(ext/web): Don't rely on NaN comparisons in `TextEncoderStream` (#13151) In the `transform` function to `TextEncoderStream`'s internal `TransformStream`, if `chunk` is the empty string and `this.#pendingHighSurrogate` is null, then `lastCodeUnit` will be NaN. As it turns out, this does not cause a bug because the comparison to check for lone surrogates turns out to be false for NaN, but to rely on it makes the code brittle. --- ext/web/08_text_encoding.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index d2922a6d45af9d..6929097262cdae 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -292,6 +292,9 @@ transform: (chunk, controller) => { try { chunk = webidl.converters.DOMString(chunk); + if (chunk === "") { + return PromiseResolve(); + } if (this.#pendingHighSurrogate !== null) { chunk = this.#pendingHighSurrogate + chunk; }