From 5948d464114c8ef917c939be85a3f1c0877ebb2a Mon Sep 17 00:00:00 2001 From: Konstantin Ulitin Date: Wed, 9 Mar 2016 18:01:05 +0300 Subject: [PATCH] WEB-20680 ES6 unicode code points escape sequences are not supported in strings --- .../intellij/lexer/StringLiteralLexer.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/platform/core-api/src/com/intellij/lexer/StringLiteralLexer.java b/platform/core-api/src/com/intellij/lexer/StringLiteralLexer.java index 3b943b9e6018..3703409fcf23 100644 --- a/platform/core-api/src/com/intellij/lexer/StringLiteralLexer.java +++ b/platform/core-api/src/com/intellij/lexer/StringLiteralLexer.java @@ -32,13 +32,13 @@ public class StringLiteralLexer extends LexerBase { public static final char NO_QUOTE_CHAR = (char)-1; - private CharSequence myBuffer; - private int myStart; - private int myEnd; + protected CharSequence myBuffer; + protected int myStart; + protected int myEnd; private int myState; private int myLastState; - private int myBufferEnd; - private final char myQuoteChar; + protected int myBufferEnd; + protected final char myQuoteChar; private final IElementType myOriginalLiteralToken; private final boolean myCanEscapeEolOrFramingSpaces; private final String myAdditionalValidEscapes; @@ -114,10 +114,7 @@ public class StringLiteralLexer extends LexerBase { return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; } if (nextChar == 'u') { - for(int i = myStart + 2; i < myStart + 6; i++) { - if (i >= myEnd || !StringUtil.isHexDigit(myBuffer.charAt(i))) return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; - } - return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; + return getUnicodeEscapeSequenceType(); } if (nextChar == 'x' && myAllowHex) { @@ -155,6 +152,14 @@ public class StringLiteralLexer extends LexerBase { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; } + @NotNull + protected IElementType getUnicodeEscapeSequenceType() { + for (int i = myStart + 2; i < myStart + 6; i++) { + if (i >= myEnd || !StringUtil.isHexDigit(myBuffer.charAt(i))) return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; + } + return StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN; + } + // all subsequent chars are escaped spaces private boolean isTrailingSpace(final int start) { for (int i=start;i