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

Side by Side Diff: Source/core/html/HTMLTextAreaElement.cpp

Issue 656683005: Use parseHTMLInteger for parsing minlength and maxlength in <textarea> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add layout tests that check for leading non-ASCII whitespaces in min/maxlength attribute Created 6 years, 2 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/textarea-minlength-expected.txt ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 25 matching lines...) Expand all
36 #include "core/dom/shadow/ShadowRoot.h" 36 #include "core/dom/shadow/ShadowRoot.h"
37 #include "core/editing/FrameSelection.h" 37 #include "core/editing/FrameSelection.h"
38 #include "core/editing/SpellChecker.h" 38 #include "core/editing/SpellChecker.h"
39 #include "core/editing/TextIterator.h" 39 #include "core/editing/TextIterator.h"
40 #include "core/events/BeforeTextInsertedEvent.h" 40 #include "core/events/BeforeTextInsertedEvent.h"
41 #include "core/events/Event.h" 41 #include "core/events/Event.h"
42 #include "core/frame/FrameHost.h" 42 #include "core/frame/FrameHost.h"
43 #include "core/frame/LocalFrame.h" 43 #include "core/frame/LocalFrame.h"
44 #include "core/html/FormDataList.h" 44 #include "core/html/FormDataList.h"
45 #include "core/html/forms/FormController.h" 45 #include "core/html/forms/FormController.h"
46 #include "core/html/parser/HTMLParserIdioms.h"
46 #include "core/html/shadow/ShadowElementNames.h" 47 #include "core/html/shadow/ShadowElementNames.h"
47 #include "core/html/shadow/TextControlInnerElements.h" 48 #include "core/html/shadow/TextControlInnerElements.h"
48 #include "core/page/Chrome.h" 49 #include "core/page/Chrome.h"
49 #include "core/page/ChromeClient.h" 50 #include "core/page/ChromeClient.h"
50 #include "core/rendering/RenderTextControlMultiLine.h" 51 #include "core/rendering/RenderTextControlMultiLine.h"
51 #include "platform/text/PlatformLocale.h" 52 #include "platform/text/PlatformLocale.h"
52 #include "wtf/StdLibExtras.h" 53 #include "wtf/StdLibExtras.h"
53 #include "wtf/text/StringBuilder.h" 54 #include "wtf/text/StringBuilder.h"
54 55
55 namespace blink { 56 namespace blink {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 value.replace('\r', '\n'); 442 value.replace('\r', '\n');
442 443
443 insertBefore(document().createTextNode(value), firstChild(), IGNORE_EXCEPTIO N); 444 insertBefore(document().createTextNode(value), firstChild(), IGNORE_EXCEPTIO N);
444 445
445 if (!m_isDirty) 446 if (!m_isDirty)
446 setNonDirtyValue(value); 447 setNonDirtyValue(value);
447 } 448 }
448 449
449 int HTMLTextAreaElement::maxLength() const 450 int HTMLTextAreaElement::maxLength() const
450 { 451 {
451 bool ok; 452 int value;
452 int value = getAttribute(maxlengthAttr).toInt(&ok); 453 if (!parseHTMLInteger(getAttribute(maxlengthAttr), value))
453 return ok && value >= 0 ? value : -1; 454 return -1;
455 return value >= 0 ? value : -1;
454 } 456 }
455 457
456 int HTMLTextAreaElement::minLength() const 458 int HTMLTextAreaElement::minLength() const
457 { 459 {
458 bool ok; 460 int value;
459 int value = getAttribute(minlengthAttr).string().toInt(&ok); 461 if (!parseHTMLInteger(getAttribute(minlengthAttr), value))
460 return ok && value >= 0 ? value : -1; 462 return -1;
463 return value >= 0 ? value : -1;
461 } 464 }
462 465
463 void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionState& exceptionSt ate) 466 void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionState& exceptionSt ate)
464 { 467 {
465 int min = minLength(); 468 int min = minLength();
466 if (newValue < 0) 469 if (newValue < 0)
467 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0."); 470 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(newValue) + ") is not positive or 0.");
468 else if (min >= 0 && newValue < min) 471 else if (min >= 0 && newValue < min)
469 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMinimumBound("maxLength", newValue, min)); 472 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMinimumBound("maxLength", newValue, min));
470 else 473 else
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 { 626 {
624 return true; 627 return true;
625 } 628 }
626 629
627 bool HTMLTextAreaElement::supportsAutofocus() const 630 bool HTMLTextAreaElement::supportsAutofocus() const
628 { 631 {
629 return true; 632 return true;
630 } 633 }
631 634
632 } 635 }
OLDNEW
« no previous file with comments | « LayoutTests/fast/forms/textarea-minlength-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698