From: Lars Knoll Date: Fri, 3 May 2013 20:38:57 +0000 (+0200) Subject: Various fixes to RegExp X-Git-Tag: upstream/5.2.1~669^2~577 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8095a376f301c2fc6f8e98d269ef100772283392;p=platform%2Fupstream%2Fqtdeclarative.git Various fixes to RegExp Duplicated pattern flags in regexp literals should lead to a parse error Make sure RegExpObjects created from a QRegExp have proper type and vtable Fix RegExp constructor when invoked with an empty pattern Fixes two qjsengine autotests. Change-Id: Idbb7dde73f20cb81dea4a07cf0f2cb030aee321b Reviewed-by: Simon Hausmann --- diff --git a/src/qml/qml/parser/qqmljslexer.cpp b/src/qml/qml/parser/qqmljslexer.cpp index cb78238..a441504 100644 --- a/src/qml/qml/parser/qqmljslexer.cpp +++ b/src/qml/qml/parser/qqmljslexer.cpp @@ -1037,7 +1037,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix) _patternFlags = 0; while (isIdentLetter(_char)) { int flag = regExpFlagFromChar(_char); - if (flag == 0) { + if (flag == 0 || _patternFlags & flag) { _errorMessage = QCoreApplication::translate("QQmlParser", "Invalid regular expression flag '%0'") .arg(QChar(_char)); return false; diff --git a/src/qml/qml/v4/qv4regexpobject.cpp b/src/qml/qml/v4/qv4regexpobject.cpp index 00f3ce3..1a8f05c 100644 --- a/src/qml/qml/v4/qv4regexpobject.cpp +++ b/src/qml/qml/v4/qv4regexpobject.cpp @@ -95,6 +95,9 @@ RegExpObject::RegExpObject(ExecutionEngine *engine, const QRegExp &re) , value(0) , global(false) { + vtbl = &static_vtbl; + type = Type_RegExpObject; + // Convert the pattern to a ECMAScript pattern. QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax()); if (re.isMinimal()) { @@ -184,10 +187,12 @@ Value RegExpCtor::construct(Managed *, ExecutionContext *ctx, Value *argv, int a return Value::fromObject(o); } - if (r.isUndefined()) - r = Value::fromString(ctx, QString()); - else if (!r.isString()) - r = __qmljs_to_string(r, ctx); + QString pattern; + if (!r.isUndefined()) + pattern = r.toString(ctx)->toQString(); + // See sec 15.10.4.1 + if (pattern.isEmpty()) + pattern = QStringLiteral("(?:)"); bool global = false; bool ignoreCase = false; @@ -208,7 +213,7 @@ Value RegExpCtor::construct(Managed *, ExecutionContext *ctx, Value *argv, int a } } - RegExp* re = RegExp::create(ctx->engine, r.stringValue()->toQString(), ignoreCase, multiLine); + RegExp* re = RegExp::create(ctx->engine, pattern, ignoreCase, multiLine); if (!re->isValid()) ctx->throwSyntaxError(0);