diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-28 07:23:31 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-28 09:22:59 (GMT) |
commit | a10d523c5010e46b86a74d111342b1b26891cbdf (patch) | |
tree | 06d7ca39e751bc8441f262f0be14b2385795fcba | |
parent | 102493fd341a322a369d21414fdb10aedaf23ff5 (diff) | |
download | Qt-a10d523c5010e46b86a74d111342b1b26891cbdf.zip Qt-a10d523c5010e46b86a74d111342b1b26891cbdf.tar.gz Qt-a10d523c5010e46b86a74d111342b1b26891cbdf.tar.bz2 |
Change JavaScriptCore so it throw error when passing invalid regexp flag
As specified in the specification.
The QScriptEngine::newRegExp on the other hand used to work with invalid
flags.
Reviewed-by: Kent Hansen
-rw-r--r-- | src/3rdparty/webkit/JavaScriptCore/runtime/RegExp.cpp | 21 | ||||
-rw-r--r-- | src/script/api/qscriptengine.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 8 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/RegExp.cpp b/src/3rdparty/webkit/JavaScriptCore/runtime/RegExp.cpp index 7dd4a8f..95a5714 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/RegExp.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/RegExp.cpp @@ -72,12 +72,33 @@ inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern, const US { // NOTE: The global flag is handled on a case-by-case basis by functions like // String::match and RegExpObject::match. +#ifndef QT_BUILD_SCRIPT_LIB if (flags.find('g') != -1) m_flagBits |= Global; if (flags.find('i') != -1) m_flagBits |= IgnoreCase; if (flags.find('m') != -1) m_flagBits |= Multiline; +#else //Invalid flags should throw a SyntaxError (ECMA Script 15.10.4.1) + static const char flagError[] = "invalid regular expression flag"; + for (int i = 0; i < flags.size(); i++) { + switch (flags.data()[i]) { + case 'g': + m_flagBits |= Global; + break; + case 'i': + m_flagBits |= IgnoreCase; + break; + case 'm': + m_flagBits |= Multiline; + break; + default: + m_constructionError = flagError; + m_regExp = 0; + return; + } + } +#endif compile(globalData); } diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 6814931..ba1a31f 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1932,7 +1932,14 @@ QScriptValue QScriptEngine::newRegExp(const QString &pattern, const QString &fla JSC::JSValue buf[2]; JSC::ArgList args(buf, sizeof(buf)); JSC::UString jscPattern = QScript::qtStringToJSCUString(pattern); - JSC::UString jscFlags = QScript::qtStringToJSCUString(flags); + QString strippedFlags; + if (flags.contains(QLatin1Char('i'))) + strippedFlags += QLatin1Char('i'); + if (flags.contains(QLatin1Char('m'))) + strippedFlags += QLatin1Char('m'); + if (flags.contains(QLatin1Char('g'))) + strippedFlags += QLatin1Char('g'); + JSC::UString jscFlags = QScript::qtStringToJSCUString(strippedFlags); buf[0] = JSC::jsString(exec, jscPattern); buf[1] = JSC::jsString(exec, jscFlags); JSC::JSObject* result = JSC::constructRegExp(exec, args); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index d657749..b52051f 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -491,16 +491,12 @@ void tst_QScriptEngine::newRegExp() QVERIFY(!r5.strictlyEquals(r)); QScriptValue r6 = rxCtor.construct(QScriptValueList() << "foo" << "bar"); - QEXPECT_FAIL("", "JSC doesn't throw error for invalid regexp flags", Continue); QVERIFY(r6.isError()); - QEXPECT_FAIL("", "JSC doesn't throw error for invalid regexp flags", Continue); - QCOMPARE(r6.toString(), QString::fromLatin1("SyntaxError: invalid regular expression flag 'b'")); + QCOMPARE(r6.toString(), QString::fromLatin1("SyntaxError: Invalid regular expression: invalid regular expression flag")); QScriptValue r7 = eng.evaluate("/foo/gimp"); - QEXPECT_FAIL("", "JSC doesn't throw error for invalid regexp flags", Continue); QVERIFY(r7.isError()); - QEXPECT_FAIL("", "JSC doesn't throw error for invalid regexp flags", Continue); - QCOMPARE(r7.toString(), QString::fromLatin1("SyntaxError: Invalid regular expression flag 'p'")); + QCOMPARE(r7.toString(), QString::fromLatin1("SyntaxError: Invalid regular expression: invalid regular expression flag")); QScriptValue r8 = eng.evaluate("/foo/migmigmig"); QVERIFY(r8.isRegExp()); |