MCPcopy Create free account
hub / github.com/microsoft/SandDance / testRegExp

Function testRegExp

docs/app/js/sanddance-app.js:143873–143900  ·  view source on GitHub ↗
(pattern, flags)

Source from the content-addressed store, hash-verified

143871 };
143872}
143873function testRegExp(pattern, flags) {
143874 let tmp = pattern;
143875 if (flags.indexOf("u") >= 0) // Replace each astral symbol and every Unicode code point
143876 // escape sequence with a single ASCII symbol to avoid throwing on
143877 // regular expressions that are only valid in combination with the
143878 // `/u` flag.
143879 // Note: replacing with the ASCII symbol `x` might cause false
143880 // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
143881 // perfectly valid pattern that is equivalent to `[a-b]`, but it
143882 // would be replaced by `[x-b]` which throws an error.
143883 tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, ($0, $1)=>{
143884 if (parseInt($1, 16) <= 0x10FFFF) return "x";
143885 throwError({}, MessageInvalidRegExp);
143886 }).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
143887 // First, detect invalid regular expressions.
143888 try {
143889 new RegExp(tmp);
143890 } catch (e) {
143891 throwError({}, MessageInvalidRegExp);
143892 } // Return a regular expression object for this pattern-flag pair, or
143893 // `null` in case the current environment doesn't support the flags it
143894 // uses.
143895 try {
143896 return new RegExp(pattern, flags);
143897 } catch (exception) {
143898 return null;
143899 }
143900}
143901function scanRegExpBody() {
143902 var ch, str, classMarker, terminated, body;
143903 ch = source[index];

Callers 1

scanRegExpFunction · 0.70

Calls 2

replaceMethod · 0.80
throwErrorFunction · 0.70

Tested by

no test coverage detected