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

Side by Side Diff: Source/core/html/forms/TextFieldInputType.cpp

Issue 189843008: Value sanitization for input[type=text] should not truncate a value at control character (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@bug196640
Patch Set: Updated as per review comments Created 6 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 unified diff | Download patch
« no previous file with comments | « LayoutTests/fast/forms/paste-multiline-text-input.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 392 }
393 393
394 static bool isASCIILineBreak(UChar c) 394 static bool isASCIILineBreak(UChar c)
395 { 395 {
396 return c == '\r' || c == '\n'; 396 return c == '\r' || c == '\n';
397 } 397 }
398 398
399 static String limitLength(const String& string, unsigned maxLength) 399 static String limitLength(const String& string, unsigned maxLength)
400 { 400 {
401 unsigned newLength = std::min(maxLength, string.length()); 401 unsigned newLength = std::min(maxLength, string.length());
402 // FIXME: We should not truncate the string at a control character. It's not
403 // compatible with IE and Firefox.
404 for (unsigned i = 0; i < newLength; ++i) {
405 const UChar current = string[i];
406 if (current < ' ' && current != '\t') {
407 newLength = i;
408 break;
409 }
410 }
411 if (newLength == string.length()) 402 if (newLength == string.length())
412 return string; 403 return string;
413 if (newLength > 0 && U16_IS_LEAD(string[newLength - 1])) 404 if (newLength > 0 && U16_IS_LEAD(string[newLength - 1]))
414 --newLength; 405 --newLength;
415 return string.left(newLength); 406 return string.left(newLength);
416 } 407 }
417 408
418 String TextFieldInputType::sanitizeValue(const String& proposedValue) const 409 String TextFieldInputType::sanitizeValue(const String& proposedValue) const
419 { 410 {
420 return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInp utElement::maximumLength); 411 return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInp utElement::maximumLength);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 { 550 {
560 return !element().isDisabledOrReadOnly(); 551 return !element().isDisabledOrReadOnly();
561 } 552 }
562 553
563 bool TextFieldInputType::shouldSpinButtonRespondToWheelEvents() 554 bool TextFieldInputType::shouldSpinButtonRespondToWheelEvents()
564 { 555 {
565 return shouldSpinButtonRespondToMouseEvents() && element().focused(); 556 return shouldSpinButtonRespondToMouseEvents() && element().focused();
566 } 557 }
567 558
568 } // namespace WebCore 559 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/forms/paste-multiline-text-input.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698