diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-10-04 17:28:17 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-04 17:28:17 +0000 |
commit | d86d6a737e2b7f51a6ac245b611e32bf0fc25d29 (patch) | |
tree | a5277fae793b11e53eb958e5f9e6895bda892978 /xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp | |
parent | 912f2d154162cef0dcb59f030a45b1f4f024f78a (diff) | |
download | pdfium-d86d6a737e2b7f51a6ac245b611e32bf0fc25d29.tar.xz |
Reject argument lists that are not comma separated
The FormCalc grammar explicitly calls out that argument lists must
have commas separating the simple expressions that make up the
elements. The current implementation will accept the invalid string
!a!b!c, which is 3 variables; !a, !b, and !c.
BUG=chromium:890407
Change-Id: I3e2da4abce9989e9e9b929ce2da030e0f8dfd371
Reviewed-on: https://pdfium-review.googlesource.com/c/43430
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp index b6517c1466..e1e001eea3 100644 --- a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp @@ -392,3 +392,126 @@ return pfm_rt.get_val(pfm_ret); EXPECT_TRUE(ast->ToJavaScript(&buf)); EXPECT_STREQ(ret, buf.MakeString().c_str()); } + +TEST(CXFA_FMParserTest, ParseFunctionCallNoArguments) { + const wchar_t input[] = L"P.x()"; + const wchar_t ret[] = + LR"***((function() { +let pfm_method_runner = function(obj, cb) { + if (pfm_rt.is_ary(obj)) { + let pfm_method_return = null; + for (var idx = obj.length -1; idx > 1; idx--) { + pfm_method_return = cb(obj[idx]); + } + return pfm_method_return; + } + return cb(obj); +}; +var pfm_ret = null; +pfm_ret = pfm_rt.get_val((function() { + return pfm_method_runner(P, function(obj) { + return obj.x(); + }); +}).call(this)); +return pfm_rt.get_val(pfm_ret); +}).call(this);)***"; + + auto parser = pdfium::MakeUnique<CXFA_FMParser>(input); + std::unique_ptr<CXFA_FMAST> ast = parser->Parse(); + EXPECT_FALSE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); + CFX_WideTextBuf buf; + EXPECT_TRUE(ast->ToJavaScript(&buf)); + EXPECT_STREQ(ret, buf.MakeString().c_str()); +} + +TEST(CXFA_FMParserTest, ParseFunctionCallSingleArgument) { + const wchar_t input[] = L"P.x(foo)"; + const wchar_t ret[] = + LR"***((function() { +let pfm_method_runner = function(obj, cb) { + if (pfm_rt.is_ary(obj)) { + let pfm_method_return = null; + for (var idx = obj.length -1; idx > 1; idx--) { + pfm_method_return = cb(obj[idx]); + } + return pfm_method_return; + } + return cb(obj); +}; +var pfm_ret = null; +pfm_ret = pfm_rt.get_val((function() { + return pfm_method_runner(P, function(obj) { + return obj.x(pfm_rt.get_jsobj(foo)); + }); +}).call(this)); +return pfm_rt.get_val(pfm_ret); +}).call(this);)***"; + + auto parser = pdfium::MakeUnique<CXFA_FMParser>(input); + std::unique_ptr<CXFA_FMAST> ast = parser->Parse(); + EXPECT_FALSE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); + CFX_WideTextBuf buf; + EXPECT_TRUE(ast->ToJavaScript(&buf)); + EXPECT_STREQ(ret, buf.MakeString().c_str()); +} + +TEST(CXFA_FMParserTest, ParseFunctionCallMultipleArguments) { + const wchar_t input[] = L"P.x(foo, bar, baz)"; + const wchar_t ret[] = + LR"***((function() { +let pfm_method_runner = function(obj, cb) { + if (pfm_rt.is_ary(obj)) { + let pfm_method_return = null; + for (var idx = obj.length -1; idx > 1; idx--) { + pfm_method_return = cb(obj[idx]); + } + return pfm_method_return; + } + return cb(obj); +}; +var pfm_ret = null; +pfm_ret = pfm_rt.get_val((function() { + return pfm_method_runner(P, function(obj) { + return obj.x(pfm_rt.get_jsobj(foo), pfm_rt.get_val(bar), pfm_rt.get_val(baz)); + }); +}).call(this)); +return pfm_rt.get_val(pfm_ret); +}).call(this);)***"; + + auto parser = pdfium::MakeUnique<CXFA_FMParser>(input); + std::unique_ptr<CXFA_FMAST> ast = parser->Parse(); + EXPECT_FALSE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); + CFX_WideTextBuf buf; + EXPECT_TRUE(ast->ToJavaScript(&buf)); + EXPECT_STREQ(ret, buf.MakeString().c_str()); +} + +TEST(CXFA_FMParserTest, ParseFunctionCallMissingCommas) { + const wchar_t input[] = L"P.x(!foo!bar!baz)"; + + auto parser = pdfium::MakeUnique<CXFA_FMParser>(input); + std::unique_ptr<CXFA_FMAST> ast = parser->Parse(); + ASSERT_TRUE(ast == nullptr); + EXPECT_TRUE(parser->HasError()); +} + +TEST(CXFA_FMParserTest, ParseFunctionCallTrailingComma) { + const wchar_t input[] = L"P.x(foo,bar,baz,)"; + + auto parser = pdfium::MakeUnique<CXFA_FMParser>(input); + std::unique_ptr<CXFA_FMAST> ast = parser->Parse(); + ASSERT_TRUE(ast == nullptr); + EXPECT_TRUE(parser->HasError()); +} + +TEST(CXFA_FMParserTest, ParseFunctionCallExtraComma) { + const wchar_t input[] = L"P.x(foo,bar,,baz)"; + + auto parser = pdfium::MakeUnique<CXFA_FMParser>(input); + std::unique_ptr<CXFA_FMAST> ast = parser->Parse(); + ASSERT_TRUE(ast == nullptr); + EXPECT_TRUE(parser->HasError()); +} |