r200540 - clang-format: (JavaScript) Don't crash on empty string literals.
Daniel Jasper
djasper at google.com
Fri Jan 31 04:49:42 PST 2014
Author: djasper
Date: Fri Jan 31 06:49:42 2014
New Revision: 200540
URL: http://llvm.org/viewvc/llvm-project?rev=200540&view=rev
Log:
clang-format: (JavaScript) Don't crash on empty string literals.
Before, this would lead to a crash:
f('', true);
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=200540&r1=200539&r2=200540&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jan 31 06:49:42 2014
@@ -1358,10 +1358,14 @@ private:
Tok.Tok.getLength());
// For formatting, treat unterminated string literals like normal string
// literals.
- if (Tok.is(tok::unknown) && !Tok.TokenText.empty() &&
- Tok.TokenText[0] == '"') {
- Tok.Tok.setKind(tok::string_literal);
- Tok.IsUnterminatedLiteral = true;
+ if (Tok.is(tok::unknown)) {
+ if (!Tok.TokenText.empty() && Tok.TokenText[0] == '"') {
+ Tok.Tok.setKind(tok::string_literal);
+ Tok.IsUnterminatedLiteral = true;
+ } else if (Style.Language == FormatStyle::LK_JavaScript &&
+ Tok.TokenText == "''") {
+ Tok.Tok.setKind(tok::char_constant);
+ }
}
}
};
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=200540&r1=200539&r2=200540&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Jan 31 06:49:42 2014
@@ -84,5 +84,9 @@ TEST_F(FormatTestJS, SpacesInContainerLi
verifyFormat("var obj = {a: 1, b: 2, c: 3};");
}
+TEST_F(FormatTestJS, SingleQuoteStrings) {
+ verifyFormat("this.function('', true);");
+}
+
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list