Skip to content

escape() is incorrect #1562

@ChALkeR

Description

@ChALkeR

Build environment: macOS
XS 16.9.1, slot 32 bytes, ID 4 bytes from jsvu

Description
escape() seems broken and does not properly escape chars

> ~/.jsvu/bin/xs -e "print(escape(String.fromCodePoint(0x80)))"                                   

> ~/.jsvu/bin/xs -e "print(escape(String.fromCodePoint(0x81)))"     

> ~/.jsvu/bin/xs -e "print(escape(String.fromCodePoint(0x80, 0x81)))"
%80%81
> ~/.jsvu/bin/xs -e "print(escape(String.fromCodePoint(0x7F)))"
%7F
> ~/.jsvu/bin/xs -e "print(escape(String.fromCodePoint(0x80, 0x42)))"
�B

0x80 and 0x81 should be always escaped, instead, the behavior depends on surrounding chars

Spec: https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-escape-string

It's in additional browser features, but if it's present it should be implemented correctly
Otherwise, feature-detecting libraries could misbehave (while e.g. not implementing this function at all would have been valid)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions