[xfa] Skip text length check for empty text fields

This CL sets the text edit engine to skip the length check when doing an
insert if the engine is currently empty. This allows handling inserting
the formatted version of strings if they have a length longer then the
maximium length.

Bug: 1066
Change-Id: If9799334f889b8ae0f568f1f9d5457e2b504aa1d
Reviewed-on: https://pdfium-review.googlesource.com/32898
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index 87dba53..3363baa 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -274,7 +274,14 @@
   // If we're going to be too big we insert what we can and notify the
   // delegate we've filled the text after the insert is done.
   bool exceeded_limit = false;
-  if (has_character_limit_ && text_length_ + length > character_limit_) {
+
+  // Currently we allow inserting a number of characters over the text limit if
+  // the text edit is already empty. This allows supporting text fields which
+  // do formatting. Otherwise, if you enter 123456789 for an SSN into a field
+  // with a 9 character limit and we reformat to 123-45-6789 we'll truncate
+  // the 89 when inserting into the text edit. See https://crbug.com/pdfium/1089
+  if (has_character_limit_ && text_length_ > 0 &&
+      text_length_ + length > character_limit_) {
     exceeded_limit = true;
     length = character_limit_ - text_length_;
   }