michael@0: /* michael@0: * Check that builtin character classes within ranges produce syntax michael@0: * errors. michael@0: * michael@0: * Note that, per the extension in bug 351463, SpiderMonkey permits hyphens michael@0: * adjacent to character class escapes in character classes, treating them as a michael@0: * hyphen pattern character. Therefore /[\d-\s]/ is okay michael@0: * michael@0: * Note: /\b/ is the backspace escape, which is a single pattern character, michael@0: * though it looks deceptively like a character class. michael@0: */ michael@0: michael@0: function isRegExpSyntaxError(pattern) { michael@0: try { michael@0: var re = new RegExp(pattern); michael@0: } catch (e) { michael@0: if (e instanceof SyntaxError) michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: assertEq(isRegExpSyntaxError('[C-\\s]'), true); michael@0: assertEq(isRegExpSyntaxError('[C-\\d]'), true); michael@0: assertEq(isRegExpSyntaxError('[C-\\W]'), true); michael@0: assertEq(isRegExpSyntaxError('[C-]'), false); michael@0: assertEq(isRegExpSyntaxError('[-C]'), false); michael@0: assertEq(isRegExpSyntaxError('[C-C]'), false); michael@0: assertEq(isRegExpSyntaxError('[C-C]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\b-\\b]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\B-\\B]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\b-\\B]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\B-\\b]'), true); michael@0: assertEq(isRegExpSyntaxError('[\\b-\\w]'), true); michael@0: assertEq(isRegExpSyntaxError('[\\B-\\w]'), true); michael@0: michael@0: /* Extension. */ michael@0: assertEq(isRegExpSyntaxError('[\\s-\\s]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\W-\\s]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\s-\\W]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\W-C]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\d-C]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\s-C]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\w-\\b]'), false); michael@0: assertEq(isRegExpSyntaxError('[\\w-\\B]'), false);