summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-08 15:20:27 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-08 15:20:27 +0000
commitdec08c8d3fbc4e89748f2d655b32727cfab373ed (patch)
tree9aac943ee5b8471322be5747d02ed8927a5ffa05 /xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
parentbda113c645673fd152bb9ca3eaddd3c34920223e (diff)
downloadpdfium-dec08c8d3fbc4e89748f2d655b32727cfab373ed.tar.xz
[fm2js] Fail transpiling if lexer has left over data
If there is remaining data after the lexer has said it's complete then something has gone wrong while lexing the formcalc data. This CL changes the transpiler to return an error in the case of the lexer havign extra data. Bug: chromium:834575 Change-Id: I8a1288a7f01cc69faf2033829d68246d815258de Reviewed-on: https://pdfium-review.googlesource.com/32130 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
index 248b9fead6..cefc1cb992 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp
@@ -15,12 +15,14 @@ TEST(CXFA_FMLexerTest, NullString) {
CXFA_FMLexer lexer(null_string);
CXFA_FMToken token = lexer.NextToken();
EXPECT_EQ(TOKeof, token.m_type);
+ EXPECT_TRUE(lexer.IsComplete());
}
TEST(CXFA_FMLexerTest, EmptyString) {
CXFA_FMLexer lexer(L"");
CXFA_FMToken token = lexer.NextToken();
EXPECT_EQ(TOKeof, token.m_type);
+ EXPECT_TRUE(lexer.IsComplete());
}
TEST(CXFA_FMLexerTest, Numbers) {
@@ -67,6 +69,7 @@ TEST(CXFA_FMLexerTest, Numbers) {
// prior to the exponent.
// EXPECT_EQ(L"100000000000000000", token.m_string);
EXPECT_EQ(L"99999999999999999", token.m_string);
+ EXPECT_TRUE(lexer->IsComplete());
}
// The quotes are stripped in CXFA_FMStringExpression::ToJavaScript.
@@ -99,6 +102,7 @@ TEST(CXFA_FMLexerTest, Strings) {
EXPECT_EQ(
L"\"\\u0047\\u006f\\u0066\\u0069\\u0073\\u0068\\u0021\\u000d\\u000a\"",
token.m_string);
+ EXPECT_TRUE(lexer->IsComplete());
}
// Note, 'this' is a keyword but is not matched by the lexer.
@@ -170,6 +174,7 @@ TEST(CXFA_FMLexerTest, OperatorsAndKeywords) {
auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(op[i].op);
CXFA_FMToken token = lexer->NextToken();
EXPECT_EQ(op[i].token, token.m_type);
+ EXPECT_TRUE(lexer->IsComplete());
}
}
@@ -213,6 +218,7 @@ TEST(CXFA_FMLexerTest, Comments) {
token = lexer->NextToken();
EXPECT_EQ(TOKeof, token.m_type);
+ EXPECT_TRUE(lexer->IsComplete());
}
TEST(CXFA_FMLexerTest, ValidIdentifiers) {
@@ -223,6 +229,7 @@ TEST(CXFA_FMLexerTest, ValidIdentifiers) {
CXFA_FMToken token = lexer->NextToken();
EXPECT_EQ(TOKidentifier, token.m_type);
EXPECT_EQ(ident, token.m_string);
+ EXPECT_TRUE(lexer->IsComplete());
}
}
@@ -248,6 +255,7 @@ TEST(CXFA_FMLexerTest, InvalidIdentifiers) {
EXPECT_NE(TOKreserver, token.m_type);
token = lexer->NextToken();
EXPECT_EQ(TOKreserver, token.m_type);
+ EXPECT_FALSE(lexer->IsComplete());
}
TEST(CXFA_FMLexerTest, Whitespace) {
@@ -266,4 +274,20 @@ TEST(CXFA_FMLexerTest, Whitespace) {
token = lexer->NextToken();
EXPECT_EQ(TOKeof, token.m_type);
+ EXPECT_TRUE(lexer->IsComplete());
+}
+
+TEST(CXFA_FMLexerTest, NullData) {
+ auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(
+ WideStringView(L"\x2d\x32\x00\x2d\x32", 5));
+ CXFA_FMToken token = lexer->NextToken();
+ EXPECT_EQ(TOKminus, token.m_type);
+
+ token = lexer->NextToken();
+ EXPECT_EQ(TOKnumber, token.m_type);
+ EXPECT_EQ(L"2", token.m_string);
+
+ token = lexer->NextToken();
+ EXPECT_EQ(TOKeof, token.m_type);
+ EXPECT_FALSE(lexer->IsComplete());
}