Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp

Issue 1846913005: Newline characters in pasted text are not counted correctly for textarea[maxlength]. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
index e63808a4969a7b87e5b3dffcd524a7bcd74cb72b..efe165004d7bc56f60c321e4eac377dff135b813 100644
--- a/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
@@ -333,9 +333,20 @@ void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*
String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue, unsigned maxLength)
{
- if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1]))
- --maxLength;
- return proposedValue.left(maxLength);
+ unsigned submissionLength = 0;
+ unsigned i = 0;
+ for (; i < proposedValue.length(); ++i) {
+ submissionLength += proposedValue[i] == '\n' ? 2 : 1;
+ if (submissionLength == maxLength) {
+ ++i;
+ break;
+ }
+ if (submissionLength > maxLength)
+ break;
+ }
+ if (i > 0 && U16_IS_LEAD(proposedValue[i - 1]))
+ --i;
+ return proposedValue.left(i);
}
void HTMLTextAreaElement::updateValue() const

Powered by Google App Engine
This is Rietveld 408576698