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

Unified Diff: Source/core/html/HTMLSelectElement.cpp

Issue 1291263003: Index setter of HTMLSelectElement and HTMLOptionsCollection should do nothing if the requested size… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update warning messages Created 5 years, 4 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
« no previous file with comments | « LayoutTests/fast/forms/select-max-length-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLSelectElement.cpp
diff --git a/Source/core/html/HTMLSelectElement.cpp b/Source/core/html/HTMLSelectElement.cpp
index a1305e285839e0d4f038c3507a3a0a1f5e45925e..93af0b216963e078bdb62f8c9b3a07511ae8bae7 100644
--- a/Source/core/html/HTMLSelectElement.cpp
+++ b/Source/core/html/HTMLSelectElement.cpp
@@ -51,6 +51,7 @@
#include "core/html/HTMLOptionElement.h"
#include "core/html/forms/FormController.h"
#include "core/input/EventHandler.h"
+#include "core/inspector/ConsoleMessage.h"
#include "core/layout/HitTestRequest.h"
#include "core/layout/HitTestResult.h"
#include "core/layout/LayoutListBox.h"
@@ -467,8 +468,11 @@ HTMLOptionElement* HTMLSelectElement::item(unsigned index)
void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, ExceptionState& exceptionState)
{
- if (index > maxSelectItems - 1)
- index = maxSelectItems - 1;
+ if (index >= length() && index >= maxSelectItems) {
+ document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel,
+ String::format("Blocked to expand the option list and set an option at index=%u. The maximum list length is %u.", index, maxSelectItems)));
+ return;
+ }
int diff = index - length();
HTMLOptionElementOrHTMLOptGroupElement element;
element.setHTMLOptionElement(option);
@@ -491,8 +495,11 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc
void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionState)
{
- if (newLen > maxSelectItems)
+ if (newLen > length() && newLen > maxSelectItems) {
+ document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel,
+ String::format("Blocked to expand the option list to %u items. The maximum list length is %u.", newLen, maxSelectItems)));
return;
+ }
int diff = length() - newLen;
if (diff < 0) { // Add dummy elements.
« no previous file with comments | « LayoutTests/fast/forms/select-max-length-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698