From fc4fd6cb029b3be7de60b8ae285d13b14b0e622b Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 26 Aug 2023 13:26:24 +1200 Subject: [PATCH] LibWeb: Fix empty value attribute for 'file' input returning fakepath It should be returning the empty string for this case. --- Tests/LibWeb/Text/expected/input-element-file-value.txt | 1 + Tests/LibWeb/Text/input/input-element-file-value.html | 8 ++++++++ Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/input-element-file-value.txt create mode 100644 Tests/LibWeb/Text/input/input-element-file-value.html diff --git a/Tests/LibWeb/Text/expected/input-element-file-value.txt b/Tests/LibWeb/Text/expected/input-element-file-value.txt new file mode 100644 index 0000000000..05f6f8ddac --- /dev/null +++ b/Tests/LibWeb/Text/expected/input-element-file-value.txt @@ -0,0 +1 @@ +value = '' diff --git a/Tests/LibWeb/Text/input/input-element-file-value.html b/Tests/LibWeb/Text/input/input-element-file-value.html new file mode 100644 index 0000000000..4ee25c4171 --- /dev/null +++ b/Tests/LibWeb/Text/input/input-element-file-value.html @@ -0,0 +1,8 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index fe028d0b2c..474bcafc58 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -304,9 +304,10 @@ DeprecatedString HTMLInputElement::value() const if (type_state() == TypeAttributeState::FileUpload) { // NOTE: This "fakepath" requirement is a sad accident of history. See the example in the File Upload state section for more information. // NOTE: Since path components are not permitted in filenames in the list of selected files, the "\fakepath\" cannot be mistaken for a path component. + // On getting, return the string "C:\fakepath\" followed by the name of the first file in the list of selected files, if any, or the empty string if the list is empty. if (m_selected_files && m_selected_files->item(0)) return DeprecatedString::formatted("C:\\fakepath\\{}", m_selected_files->item(0)->name()); - return "C:\\fakepath\\"sv; + return DeprecatedString::empty(); } // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-value