Skip to content

Commit

Permalink
introduce HtmlInput.getValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 1, 2022
1 parent 5e0dba0 commit 48ae803
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</properties>

<body>
<release version="2.62.0" date="May xx, 2022" description="Chrome/Edge 102, Bugfixes">
<release version="2.62.0" date="May xx, 2022" description="Chrome/Edge 102, Firefox 101, Bugfixes">
<action> type="add" dev="rbri">
Introduce HtmlInput.getValue().
</action>
<action type="fix" dev="rbri" due-to="Rural Hunter">
core-js: Fix Object.getOwnPropertyDescriptors by fixing missing scope definitions.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ public String getContentType() {
return contentType_;
}

/**
* {@inheritDoc}
*/
@Override
public String getValue() {
final File[] files = getFiles();
if (files == null || files.length == 0) {
return ATTRIBUTE_NOT_DEFINED;
}
final File first = files[0];
final String name = first.getName();
if (name.isEmpty()) {
return name;
}
return "C:\\fakepath\\" + name;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ public final String getValueAttribute() {
return getAttributeDirect("value");
}

/**
* @return the value
*/
public String getValue() {
return getValueAttribute();
}

/**
* Returns the value of the attribute {@code checked}. Refer to the
* <a href='http://www.w3.org/TR/html401/'>HTML 4.01</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR;
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

Expand Down Expand Up @@ -669,30 +668,17 @@ public void setSrc(final String src) {
@Override
public String getValue() {
final HtmlInput htmlInput = getDomNodeOrDie();
if (htmlInput instanceof HtmlFileInput) {
final File[] files = ((HtmlFileInput) htmlInput).getFiles();
if (files == null || files.length == 0) {
return ATTRIBUTE_NOT_DEFINED;
}
final File first = files[0];
final String name = first.getName();
if (name.isEmpty()) {
return name;
}
return "C:\\fakepath\\" + name;
}

if (htmlInput instanceof HtmlNumberInput) {
final HtmlNumberInput htmlNumberInput = (HtmlNumberInput) htmlInput;
final String valueAttr = htmlInput.getAttributeDirect("value");
final String valueAttr = htmlInput.getValue();
if (!valueAttr.isEmpty()) {
if ("-".equals(valueAttr) || "+".equals(valueAttr)) {
return "";
}

final int lastPos = valueAttr.length() - 1;
if (lastPos >= 0 && valueAttr.charAt(lastPos) == '.') {
if (htmlNumberInput.hasFeature(JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE)) {
if (htmlInput.hasFeature(JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE)) {
return "";
}
}
Expand All @@ -705,7 +691,7 @@ public String getValue() {
}
}

return htmlInput.getAttributeDirect("value");
return htmlInput.getValue();
}

/**
Expand Down

0 comments on commit 48ae803

Please sign in to comment.