summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r--xfa/fxfa/fm2js/xfa_simpleexpression.cpp41
-rw-r--r--xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp33
2 files changed, 54 insertions, 20 deletions
diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp
index 872fe7e2e8..fabdaa60f0 100644
--- a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp
+++ b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp
@@ -153,28 +153,29 @@ CXFA_FMStringExpression::~CXFA_FMStringExpression() {}
void CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
CFX_WideString tempStr(m_wsString);
- if (tempStr.GetLength() > 2) {
- javascript.AppendChar(L'\"');
- wchar_t oneChar;
- for (int16_t i = 1; i < tempStr.GetLength() - 1; i++) {
- oneChar = tempStr[i];
- switch (oneChar) {
- case L'\"': {
- i++;
- javascript << L"\\\"";
- } break;
- case 0x0d:
- break;
- case 0x0a: {
- javascript << L"\\n";
- } break;
- default: { javascript.AppendChar(oneChar); } break;
- }
- }
- javascript.AppendChar(L'\"');
- } else {
+ if (tempStr.GetLength() <= 2) {
javascript << tempStr;
+ return;
+ }
+ javascript.AppendChar(L'\"');
+ for (int32_t i = 1; i < tempStr.GetLength() - 1; i++) {
+ wchar_t oneChar = tempStr[i];
+ switch (oneChar) {
+ case L'\"':
+ i++;
+ javascript << L"\\\"";
+ break;
+ case 0x0d:
+ break;
+ case 0x0a:
+ javascript << L"\\n";
+ break;
+ default:
+ javascript.AppendChar(oneChar);
+ break;
+ }
}
+ javascript.AppendChar(L'\"');
}
CXFA_FMIdentifierExpression::CXFA_FMIdentifierExpression(
diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp
index 160c4a12c4..b1b96e03d5 100644
--- a/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp
+++ b/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp
@@ -7,6 +7,7 @@
#include <memory>
#include <utility>
+#include "core/fxcrt/fx_string.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
#include "third_party/base/ptr_util.h"
@@ -41,3 +42,35 @@ TEST(FMCallExpressionTest, more_than_32_arguments) {
EXPECT_EQ(result.AsStringC(), js.AsStringC());
}
+
+TEST(FMStringExpressionTest, Empty) {
+ CFX_WideTextBuf accumulator;
+ CXFA_FMStringExpression(1, CFX_WideStringC()).ToJavaScript(accumulator);
+ EXPECT_EQ(L"", accumulator.AsStringC());
+}
+
+TEST(FMStringExpressionTest, Short) {
+ CFX_WideTextBuf accumulator;
+ CXFA_FMStringExpression(1, L"a").ToJavaScript(accumulator);
+ EXPECT_EQ(L"a", accumulator.AsStringC());
+}
+
+TEST(FMStringExpressionTest, Medium) {
+ CFX_WideTextBuf accumulator;
+ CXFA_FMStringExpression(1, L".abcd.").ToJavaScript(accumulator);
+ EXPECT_EQ(L"\"abcd\"", accumulator.AsStringC());
+}
+
+TEST(FMStringExpressionTest, Long) {
+ CFX_WideTextBuf accumulator;
+ std::vector<CFX_WideStringC::UnsignedType> vec(140000, L'A');
+ CXFA_FMStringExpression(1, CFX_WideStringC(vec)).ToJavaScript(accumulator);
+ EXPECT_EQ(140000, accumulator.GetLength());
+}
+
+TEST(FMStringExpressionTest, Quoted) {
+ CFX_WideTextBuf accumulator;
+ CXFA_FMStringExpression(1, L".Simon says \"\"run\"\".")
+ .ToJavaScript(accumulator);
+ EXPECT_EQ(L"\"Simon says \\\"run\\\"\"", accumulator.AsStringC());
+}