Skip to content

Commit

Permalink
avoid duplicated entries
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Oct 2, 2023
1 parent 1930190 commit 01a643b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 70 deletions.
69 changes: 4 additions & 65 deletions src/main/java/org/htmlunit/html/HtmlForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static java.nio.charset.StandardCharsets.UTF_16;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.htmlunit.BrowserVersionFeatures.FORM_FORM_ATTRIBUTE_SUPPORTED;
import static org.htmlunit.BrowserVersionFeatures.FORM_PARAMETRS_NOT_SUPPORTED_FOR_IMAGE;
import static org.htmlunit.BrowserVersionFeatures.FORM_SUBMISSION_DOWNLOWDS_ALSO_IF_ONLY_HASH_CHANGED;
import static org.htmlunit.BrowserVersionFeatures.FORM_SUBMISSION_HEADER_CACHE_CONTROL_MAX_AGE;
Expand Down Expand Up @@ -464,27 +463,6 @@ Collection<SubmittableElement> getSubmittableElements(final SubmittableElement s
}
}

if (getPage().getWebClient().getBrowserVersion().hasFeature(FORM_FORM_ATTRIBUTE_SUPPORTED)) {
final String formId = getId();
if (formId != ATTRIBUTE_NOT_DEFINED) {
for (final HtmlElement element : ((HtmlPage) getPage()).getBody().getHtmlElementDescendants()) {
final String formIdRef = element.getAttribute("form");
if (formId.equals(formIdRef) && isSubmittable(element, submitElement)) {
final SubmittableElement submittable = (SubmittableElement) element;
if (!submittableElements.contains(submittable)) {
submittableElements.add(submittable);
}
}
}
}
}

for (final HtmlElement element : lostChildren_) {
if (isSubmittable(element, submitElement)) {
submittableElements.add((SubmittableElement) element);
}
}

return submittableElements;
}

Expand Down Expand Up @@ -556,15 +534,7 @@ private static boolean isSubmittable(final HtmlElement element, final Submittabl
* @return all input elements which are members of this form and have the specified name
*/
public List<HtmlInput> getInputsByName(final String name) {
final List<HtmlInput> list = getFormElementsByAttribute(HtmlInput.TAG_NAME, NAME_ATTRIBUTE, name);

// collect inputs from lost children
for (final HtmlElement elt : getLostChildren()) {
if (elt instanceof HtmlInput && name.equals(elt.getAttributeDirect(NAME_ATTRIBUTE))) {
list.add((HtmlInput) elt);
}
}
return list;
return getFormElementsByAttribute(HtmlInput.TAG_NAME, NAME_ATTRIBUTE, name);
}

/**
Expand Down Expand Up @@ -643,15 +613,7 @@ public final <I extends HtmlInput> I getInputByName(final String name) throws El
* @return all the {@link HtmlSelect} elements in this form that have the specified name
*/
public List<HtmlSelect> getSelectsByName(final String name) {
final List<HtmlSelect> list = getFormElementsByAttribute(HtmlSelect.TAG_NAME, NAME_ATTRIBUTE, name);

// collect selects from lost children
for (final HtmlElement elt : getLostChildren()) {
if (elt instanceof HtmlSelect && name.equals(elt.getAttributeDirect(NAME_ATTRIBUTE))) {
list.add((HtmlSelect) elt);
}
}
return list;
return getFormElementsByAttribute(HtmlSelect.TAG_NAME, NAME_ATTRIBUTE, name);
}

/**
Expand All @@ -677,15 +639,7 @@ public HtmlSelect getSelectByName(final String name) throws ElementNotFoundExcep
* @return all the {@link HtmlButton} elements in this form that have the specified name
*/
public List<HtmlButton> getButtonsByName(final String name) {
final List<HtmlButton> list = getFormElementsByAttribute(HtmlButton.TAG_NAME, NAME_ATTRIBUTE, name);

// collect buttons from lost children
for (final HtmlElement elt : getLostChildren()) {
if (elt instanceof HtmlButton && name.equals(elt.getAttributeDirect(NAME_ATTRIBUTE))) {
list.add((HtmlButton) elt);
}
}
return list;
return getFormElementsByAttribute(HtmlButton.TAG_NAME, NAME_ATTRIBUTE, name);
}

/**
Expand All @@ -711,15 +665,7 @@ public HtmlButton getButtonByName(final String name) throws ElementNotFoundExcep
* @return all the {@link HtmlTextArea} elements in this form that have the specified name
*/
public List<HtmlTextArea> getTextAreasByName(final String name) {
final List<HtmlTextArea> list = getFormElementsByAttribute(HtmlTextArea.TAG_NAME, NAME_ATTRIBUTE, name);

// collect buttons from lost children
for (final HtmlElement elt : getLostChildren()) {
if (elt instanceof HtmlTextArea && name.equals(elt.getAttributeDirect(NAME_ATTRIBUTE))) {
list.add((HtmlTextArea) elt);
}
}
return list;
return getFormElementsByAttribute(HtmlTextArea.TAG_NAME, NAME_ATTRIBUTE, name);
}

/**
Expand Down Expand Up @@ -991,13 +937,6 @@ public List<HtmlInput> getInputsByValue(final String value) {
}
}

for (final HtmlElement element : getLostChildren()) {
if (element instanceof HtmlInput
&& Objects.equals(((HtmlInput) element).getValue(), value)) {
results.add((HtmlInput) element);
}
}

return results;
}

Expand Down
5 changes: 0 additions & 5 deletions src/test/java/org/htmlunit/html/parser/MalformedHtmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
*/
package org.htmlunit.html.parser;

import static org.htmlunit.junit.BrowserRunner.TestedBrowser.CHROME;
import static org.htmlunit.junit.BrowserRunner.TestedBrowser.EDGE;
import static org.htmlunit.junit.BrowserRunner.TestedBrowser.FF;
import static org.htmlunit.junit.BrowserRunner.TestedBrowser.FF_ESR;

import org.htmlunit.WebDriverTestCase;
import org.htmlunit.html.HtmlPageTest;
import org.htmlunit.junit.BrowserRunner;
Expand Down

0 comments on commit 01a643b

Please sign in to comment.