REGRESSION(r164329): Input fields are not honoring the maxlength attribute
[WebKit-https.git] / Source / WebCore / html / TextFieldInputType.cpp
index 1bbad62a4d390d293db26f1a8340406922ec8a3d..e7bc28b87bab94fd0d12352af985981667c26e4a 100644 (file)
@@ -384,7 +384,10 @@ void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*
     unsigned selectionLength = 0;
     if (element().focused()) {
         ASSERT(enclosingTextFormControl(element().document().frame()->selection().selection().start()) == &element());
-        selectionLength = numGraphemeClusters(innerText.substring(element().selectionStart(), element().selectionEnd()));
+        int selectionStart = element().selectionStart();
+        ASSERT(selectionStart <= element().selectionEnd());
+        int selectionCodeUnitCount = element().selectionEnd() - selectionStart;
+        selectionLength = selectionCodeUnitCount ? numGraphemeClusters(innerText.substring(selectionStart, selectionCodeUnitCount)) : 0;
     }
     ASSERT(oldLength >= selectionLength);