mirror of
https://github.com/denoland/deno.git
synced 2025-09-30 06:04:48 +00:00
fix: atob should throw dom exception (#5730)
This commit is contained in:
parent
526c9196e2
commit
4fa69e890e
1 changed files with 5 additions and 2 deletions
|
@ -23,6 +23,7 @@
|
||||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
// OTHER DEALINGS IN THE SOFTWARE.
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import { DOMExceptionImpl as DOMException } from "./dom_exception.ts";
|
||||||
import * as base64 from "./base64.ts";
|
import * as base64 from "./base64.ts";
|
||||||
import { decodeUtf8 } from "./decode_utf8.ts";
|
import { decodeUtf8 } from "./decode_utf8.ts";
|
||||||
import { core } from "../core.ts";
|
import { core } from "../core.ts";
|
||||||
|
@ -101,8 +102,10 @@ export function atob(s: string): string {
|
||||||
|
|
||||||
const rem = s.length % 4;
|
const rem = s.length % 4;
|
||||||
if (rem === 1 || /[^+/0-9A-Za-z]/.test(s)) {
|
if (rem === 1 || /[^+/0-9A-Za-z]/.test(s)) {
|
||||||
// TODO: throw `DOMException`
|
throw new DOMException(
|
||||||
throw new TypeError("The string to be decoded is not correctly encoded");
|
"The string to be decoded is not correctly encoded",
|
||||||
|
"DataDecodeError"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// base64-js requires length exactly times of 4
|
// base64-js requires length exactly times of 4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue