diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-04-16 13:01:39 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-04-16 13:03:19 (GMT) |
commit | e23a519366587cfc27ad3be88180692cb49e206f (patch) | |
tree | 185250545e3845ccf8c84a9807f95957f95b9e7f /src/declarative/qml/parser | |
parent | 86efad03a977763c900aaa0b634f64c109a27e4f (diff) | |
download | Qt-e23a519366587cfc27ad3be88180692cb49e206f.zip Qt-e23a519366587cfc27ad3be88180692cb49e206f.tar.gz Qt-e23a519366587cfc27ad3be88180692cb49e206f.tar.bz2 |
Recognize identifiers containing unicode escape sequences.
Task-number: QTBUG-8108
Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/declarative/qml/parser')
-rw-r--r-- | src/declarative/qml/parser/qdeclarativejslexer.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index a616146..7c1c30c 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -484,6 +484,8 @@ int Lexer::lex() stackToken = -1; } + bool identifierWithEscapedUnicode = false; + while (!done) { switch (state) { case Start: @@ -523,7 +525,26 @@ int Lexer::lex() state = InString; multiLineString = false; stringType = current; + } else if (current == '\\' && next1 == 'u') { + identifierWithEscapedUnicode = true; + recordStartPos(); + + shift(2); // skip the unicode escape prefix `\u' + + if (isHexDigit(current) && isHexDigit(next1) && + isHexDigit(next2) && isHexDigit(next3)) { + record16(convertUnicode(current, next1, next2, next3)); + shift(3); + state = InIdentifier; + } else { + setDone(Bad); + err = IllegalUnicodeEscapeSequence; + errmsg = QCoreApplication::translate("QDeclarativeParser", "Illegal unicode escape sequence"); + break; + } + } else if (isIdentLetter(current)) { + identifierWithEscapedUnicode = false; recordStartPos(); record16(current); state = InIdentifier; @@ -683,6 +704,21 @@ int Lexer::lex() if (isIdentLetter(current) || isDecimalDigit(current)) { record16(current); break; + } else if (current == '\\' && next1 == 'u') { + identifierWithEscapedUnicode = true; + shift(2); // skip the unicode escape prefix `\u' + + if (isHexDigit(current) && isHexDigit(next1) && + isHexDigit(next2) && isHexDigit(next3)) { + record16(convertUnicode(current, next1, next2, next3)); + shift(3); + break; + } else { + setDone(Bad); + err = IllegalUnicodeEscapeSequence; + errmsg = QCoreApplication::translate("QDeclarativeParser", "Illegal unicode escape sequence"); + break; + } } setDone(Identifier); break; @@ -825,7 +861,11 @@ int Lexer::lex() delimited = true; return token; case Identifier: - if ((token = findReservedWord(buffer16, pos16)) < 0) { + token = -1; + if (! identifierWithEscapedUnicode) + token = findReservedWord(buffer16, pos16); + + if (token < 0) { /* TODO: close leak on parse error. same holds true for String */ if (driver) qsyylval.ustr = driver->intern(buffer16, pos16); |