Correctly handle empty input to AFPercent_Format().

Treat it like 0.

Change-Id: Ie9f8b34936448b2bf18f372bb72cef6bf6093bc3
Reviewed-on: https://pdfium-review.googlesource.com/c/51071
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Wei Li <weili@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 1811321..5f0fdfd 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -783,11 +783,6 @@
   if (!pEvent->m_pValue)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  WideString& Value = pEvent->Value();
-  ByteString strValue = StrTrim(Value.ToDefANSI());
-  if (strValue.IsEmpty())
-    return CJS_Result::Success();
-
   // Acrobat will accept this. Anything larger causes it to throw an error.
   static constexpr int kMaxSepStyle = 49;
 
@@ -798,6 +793,11 @@
 
   iSepStyle = ValidStyleOrZero(iSepStyle);
 
+  WideString& Value = pEvent->Value();
+  ByteString strValue = StrTrim(Value.ToDefANSI());
+  if (strValue.IsEmpty())
+    strValue = "0";
+
   // for processing decimal places
   double dValue = atof(strValue.c_str());
   dValue *= 100;
diff --git a/testing/resources/javascript/public_methods_expected.txt b/testing/resources/javascript/public_methods_expected.txt
index 269d1da..6131da8 100644
--- a/testing/resources/javascript/public_methods_expected.txt
+++ b/testing/resources/javascript/public_methods_expected.txt
@@ -66,9 +66,9 @@
 Alert: PASS: AFPercent_Format(1, 0, 0) = -512.3%
 Alert: FAIL: AFPercent_Format(1, 0, 1) = -512.3%, expected %-512.3 
 Alert: FAIL: AFPercent_Format(1, 0, 2) = -512.3%, expected %-512.3 
-Alert: FAIL: AFPercent_Format(10, 0, 0) = , expected 0.0000000000% 
-Alert: FAIL: AFPercent_Format(10, 0, 1) = , expected %0.0000000000 
-Alert: FAIL: AFPercent_Format(10, 0, 2) = , expected %0.0000000000 
+Alert: PASS: AFPercent_Format(10, 0, 0) = 0.0000000000%
+Alert: FAIL: AFPercent_Format(10, 0, 1) = 0.0000000000%, expected %0.0000000000 
+Alert: FAIL: AFPercent_Format(10, 0, 2) = 0.0000000000%, expected %0.0000000000 
 Alert: PASS: AFPercent_Format(-3, 0) threw AFPercent_Format: Incorrect parameter value.
 Alert: PASS: AFPercent_Format(-3, 1) threw AFPercent_Format: Incorrect parameter value.
 Alert: PASS: AFPercent_Format(-1, 3) threw AFPercent_Format: Incorrect parameter value.
@@ -76,26 +76,26 @@
 Alert: PASS: AFPercent_Format(0, -1) threw AFPercent_Format: Incorrect parameter value.
 Alert: PASS: AFPercent_Format(0, 50) threw AFPercent_Format: Incorrect parameter value.
 Alert: PASS: AFPercent_Format(0, 51) threw AFPercent_Format: Incorrect parameter value.
-Alert: FAIL: AFPercent_Format(1, 0) = , expected 0.0% 
-Alert: FAIL: AFPercent_Format(1, 1) = , expected 0.0% 
-Alert: FAIL: AFPercent_Format(1, 2) = , expected 0,0% 
-Alert: FAIL: AFPercent_Format(1, 3) = , expected 0,0% 
-Alert: FAIL: AFPercent_Format(1, 4) = , expected 0.0% 
-Alert: FAIL: AFPercent_Format(2, 0) = , expected 0.00% 
-Alert: FAIL: AFPercent_Format(2, 1) = , expected 0.00% 
-Alert: FAIL: AFPercent_Format(2, 2) = , expected 0,00% 
-Alert: FAIL: AFPercent_Format(2, 3) = , expected 0,00% 
-Alert: FAIL: AFPercent_Format(2, 4) = , expected 0.00% 
-Alert: FAIL: AFPercent_Format(3, 0) = , expected 0.000% 
-Alert: FAIL: AFPercent_Format(3, 1) = , expected 0.000% 
-Alert: FAIL: AFPercent_Format(3, 2) = , expected 0,000% 
-Alert: FAIL: AFPercent_Format(3, 3) = , expected 0,000% 
-Alert: FAIL: AFPercent_Format(3, 4) = , expected 0.000% 
-Alert: FAIL: AFPercent_Format(10, 0) = , expected 0.0000000000% 
-Alert: FAIL: AFPercent_Format(10, 1) = , expected 0.0000000000% 
-Alert: FAIL: AFPercent_Format(10, 2) = , expected 0,0000000000% 
-Alert: FAIL: AFPercent_Format(10, 3) = , expected 0,0000000000% 
-Alert: FAIL: AFPercent_Format(10, 4) = , expected 0.0000000000% 
+Alert: PASS: AFPercent_Format(1, 0) = 0.0%
+Alert: PASS: AFPercent_Format(1, 1) = 0.0%
+Alert: PASS: AFPercent_Format(1, 2) = 0,0%
+Alert: PASS: AFPercent_Format(1, 3) = 0,0%
+Alert: PASS: AFPercent_Format(1, 4) = 0.0%
+Alert: PASS: AFPercent_Format(2, 0) = 0.00%
+Alert: PASS: AFPercent_Format(2, 1) = 0.00%
+Alert: PASS: AFPercent_Format(2, 2) = 0,00%
+Alert: PASS: AFPercent_Format(2, 3) = 0,00%
+Alert: PASS: AFPercent_Format(2, 4) = 0.00%
+Alert: PASS: AFPercent_Format(3, 0) = 0.000%
+Alert: PASS: AFPercent_Format(3, 1) = 0.000%
+Alert: PASS: AFPercent_Format(3, 2) = 0,000%
+Alert: PASS: AFPercent_Format(3, 3) = 0,000%
+Alert: PASS: AFPercent_Format(3, 4) = 0.000%
+Alert: PASS: AFPercent_Format(10, 0) = 0.0000000000%
+Alert: PASS: AFPercent_Format(10, 1) = 0.0000000000%
+Alert: PASS: AFPercent_Format(10, 2) = 0,0000000000%
+Alert: PASS: AFPercent_Format(10, 3) = 0,0000000000%
+Alert: PASS: AFPercent_Format(10, 4) = 0.0000000000%
 Alert: PASS: AFPercent_Format(1, 0) = 0.0%
 Alert: PASS: AFPercent_Format(1, 1) = 0.0%
 Alert: PASS: AFPercent_Format(1, 2) = 0,0%