Skip to content

Commit 3bd1711

Browse files
committed
Remove obsolete fix for empty character classes (#319)
1 parent c429833 commit 3bd1711

File tree

2 files changed

+0
-39
lines changed

2 files changed

+0
-39
lines changed

src/xregexp.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,21 +1757,6 @@ XRegExp.addToken(
17571757
}
17581758
);
17591759

1760-
/*
1761-
* Empty character class: `[]` or `[^]`. This fixes a critical cross-browser syntax inconsistency.
1762-
* Unless this is standardized (per the ES spec), regex syntax can't be accurately parsed because
1763-
* character class endings can't be determined.
1764-
*/
1765-
XRegExp.addToken(
1766-
/\[(\^?)\]/,
1767-
// For cross-browser compatibility with ES3, convert [] to \b\B and [^] to [\s\S].
1768-
// (?!) should work like \b\B, but is unreliable in some versions of Firefox
1769-
/* eslint-disable no-confusing-arrow */
1770-
(match) => (match[1] ? '[\\s\\S]' : '\\b\\B'),
1771-
/* eslint-enable no-confusing-arrow */
1772-
{leadChar: '['}
1773-
);
1774-
17751760
/*
17761761
* Comment pattern: `(?# )`. Inline comments are an alternative to the line comments allowed in
17771762
* free-spacing mode (flag x).

tests/spec/s-xregexp.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,30 +278,6 @@ describe('XRegExp()', function() {
278278
expect(XRegExp(XRegExp(/./im))[REGEX_DATA].flags).toBeNull();
279279
});
280280

281-
describe('fixes regex syntax cross-browser:', function() {
282-
283-
it('should use the correct JavaScript rules for empty character classes', function() {
284-
285-
/* Traditional regex behavior is that a leading, unescaped ] within a character class
286-
* is treated as a literal character and does not end the character class. However,
287-
* this is not true for ES3/5, which states that [] is an empty set that will never
288-
* match (similar to (?!)) and [^] matches any single character (like [\s\S] or
289-
* [\0-\uFFFF]). IE < 9 and older versions of Safari use the traditional behavior,
290-
* rather than the correct ES3/5 behavior. Older versions of Opera reverse the correct
291-
* ES3/5 behavior, so that [] matches any character and [^] never matches. Regexes
292-
* created by XRegExp follow the ES3/5 standard behavior cross-browser.
293-
*/
294-
295-
expect(XRegExp('[]').test('a')).toBe(false);
296-
expect(XRegExp('[]]').test('a]')).toBe(false);
297-
expect(XRegExp('[]]').test(']')).toBe(false);
298-
299-
expect(XRegExp('[^]').test('a')).toBe(true);
300-
expect(XRegExp('[^]]').test('a]')).toBe(true);
301-
});
302-
303-
});
304-
305281
describe('supports new regex syntax:', function() {
306282

307283
describe('leading mode modifier', function() {

0 commit comments

Comments
 (0)