Skip to content

Remove obsolete cross-browser fix for empty character classes #319

Closed
@slevithan

Description

@slevithan

Traditional regex behavior is that a leading, unescaped ] within a character class is treated as a literal character and does not end the character class. However, this is not true for JS (at least ES3+), which states that [] is an empty set that will never match (similar to (?!)) and [^] matches any single character (like [\s\S]). Ancient versions of Internet Explorer (v <= 8) and Safari used the traditional behavior, rather than the correct ES3 behavior. Ancient versions of Opera reversed the correct ES3 behavior, so that [] matched any character and [^] never matched. Regexes created by XRegExp have always followed the ES3 standard behavior cross-browser.

This used to be a critical fix since without it you couldn't know where a character class ended, and thus could not reliably parse regex syntax. However, I think the time has come to remove this cross-browser fix, since a couple years ago XRegExp dropped support for pre-ES5 browsers, and the native fixes for this predate ES5 support. Specifically, all the browsers rushed to fix this when coverage for it was included in the Acid3 test released in 2008.

Removing the handling for this will offer a very slight perf improvement when compiling any regex with XRegExp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions