1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/basic/bug576837-regexp.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +/* 1.5 + * Check that builtin character classes within ranges produce syntax 1.6 + * errors. 1.7 + * 1.8 + * Note that, per the extension in bug 351463, SpiderMonkey permits hyphens 1.9 + * adjacent to character class escapes in character classes, treating them as a 1.10 + * hyphen pattern character. Therefore /[\d-\s]/ is okay 1.11 + * 1.12 + * Note: /\b/ is the backspace escape, which is a single pattern character, 1.13 + * though it looks deceptively like a character class. 1.14 + */ 1.15 + 1.16 +function isRegExpSyntaxError(pattern) { 1.17 + try { 1.18 + var re = new RegExp(pattern); 1.19 + } catch (e) { 1.20 + if (e instanceof SyntaxError) 1.21 + return true; 1.22 + } 1.23 + return false; 1.24 +} 1.25 + 1.26 +assertEq(isRegExpSyntaxError('[C-\\s]'), true); 1.27 +assertEq(isRegExpSyntaxError('[C-\\d]'), true); 1.28 +assertEq(isRegExpSyntaxError('[C-\\W]'), true); 1.29 +assertEq(isRegExpSyntaxError('[C-]'), false); 1.30 +assertEq(isRegExpSyntaxError('[-C]'), false); 1.31 +assertEq(isRegExpSyntaxError('[C-C]'), false); 1.32 +assertEq(isRegExpSyntaxError('[C-C]'), false); 1.33 +assertEq(isRegExpSyntaxError('[\\b-\\b]'), false); 1.34 +assertEq(isRegExpSyntaxError('[\\B-\\B]'), false); 1.35 +assertEq(isRegExpSyntaxError('[\\b-\\B]'), false); 1.36 +assertEq(isRegExpSyntaxError('[\\B-\\b]'), true); 1.37 +assertEq(isRegExpSyntaxError('[\\b-\\w]'), true); 1.38 +assertEq(isRegExpSyntaxError('[\\B-\\w]'), true); 1.39 + 1.40 +/* Extension. */ 1.41 +assertEq(isRegExpSyntaxError('[\\s-\\s]'), false); 1.42 +assertEq(isRegExpSyntaxError('[\\W-\\s]'), false); 1.43 +assertEq(isRegExpSyntaxError('[\\s-\\W]'), false); 1.44 +assertEq(isRegExpSyntaxError('[\\W-C]'), false); 1.45 +assertEq(isRegExpSyntaxError('[\\d-C]'), false); 1.46 +assertEq(isRegExpSyntaxError('[\\s-C]'), false); 1.47 +assertEq(isRegExpSyntaxError('[\\w-\\b]'), false); 1.48 +assertEq(isRegExpSyntaxError('[\\w-\\B]'), false);