Chrome's Regexes - Can I view them? Chrome's Regexes - Can I view them? google-chrome google-chrome

Chrome's Regexes - Can I view them?


I looked up the source code of Blink. Keep in mind I never saw it before today, so I might be completely off. Assuming I found the right place -

For type="url" fields there is URLInputType, with the code:

bool URLInputType::typeMismatchFor(const String& value) const{    return !value.isEmpty() && !KURL(KURL(), value).isValid();}

typeMismatchFor is called from HTMLInputElement::isValidValue

bool HTMLInputElement::isValidValue(const String& value) const{    if (!m_inputType->canSetStringValue()) {        ASSERT_NOT_REACHED();        return false;    }    return !m_inputType->typeMismatchFor(value) // <-- here        && !m_inputType->stepMismatch(value)        && !m_inputType->rangeUnderflow(value)        && !m_inputType->rangeOverflow(value)        && !tooLong(value, IgnoreDirtyFlag)        && !m_inputType->patternMismatch(value)        && !m_inputType->valueMissing(value);}

KURL seems like a proper implementation of a URL, used everywhere in Blink.

In comparison, the implementation for EmailInputType, typeMismatchFor calls isValidEmailAddress, which does use a regex:

static const char emailPattern[] =    "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part    "@"    "[a-z0-9-]+(\\.[a-z0-9-]+)*"; // domain partstatic bool isValidEmailAddress(const String& address){    int addressLength = address.length();    if (!addressLength)        return false;    DEFINE_STATIC_LOCAL(const RegularExpression, regExp,                        (emailPattern, TextCaseInsensitive));    int matchLength;    int matchOffset = regExp.match(address, 0, &matchLength);    return !matchOffset && matchLength == addressLength;}

These elements and more can be found on the /html folder. It seems most of them are using proper parsing and checking of the input, not regular expressions.