ccxvii / mujs

An embeddable Javascript interpreter in C.
http://mujs.com/
ISC License
812 stars 98 forks source link

Regular expressions of medium complexity fail: too many character classes #100

Closed yurivict closed 4 years ago

yurivict commented 5 years ago

This script fails:

var reI = "\\s*([+-]?\\d+)\\s*",
    reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
    reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
    reHex3 = /^#([0-9a-f]{3})$/,
    reHex6 = /^#([0-9a-f]{6})$/,
    reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
    reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
    reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
    reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
    reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
    reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
SyntaxError: regular expression: too many character classes
    at RegExp (native)
    at ./regexp.js:8
Mark1626 commented 5 years ago

Looks like it is from this

https://github.com/ccxvii/mujs/blob/14dc9355bd71818cf01c1c690c1c91a0978ea9b8/regexp.c#L31-L36

gardhr commented 4 years ago

@yurivict

This has been fixed in the latest version . Just define MAXCLASS to be whatever size you find acceptable (I set it to an insanely high value of 1024 just to be sure).

yurivict commented 4 years ago

Thank you!