Skip to content

Commit 3dd8b32

Browse files
skyz1tcl3
authored andcommitted
LibWeb/HTML: Only include direction if dirname applies
This commit changes form data to only include the direction of auto directionality form associated elements.
1 parent c5fc4a5 commit 3dd8b32

File tree

6 files changed

+109
-4
lines changed

6 files changed

+109
-4
lines changed

Libraries/LibWeb/DOM/Element.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ class Element
400400
Rtl,
401401
};
402402
Directionality directionality() const;
403+
bool is_auto_directionality_form_associated_element() const;
403404

404405
Optional<FlyString> const& id() const { return m_id; }
405406
Optional<FlyString> const& name() const { return m_name; }
@@ -556,7 +557,6 @@ class Element
556557
Optional<Directionality> auto_directionality() const;
557558
Optional<Directionality> contained_text_auto_directionality(bool can_exclude_root) const;
558559
Directionality parent_directionality() const;
559-
bool is_auto_directionality_form_associated_element() const;
560560

561561
QualifiedName m_qualified_name;
562562
mutable Optional<FlyString> m_html_uppercased_qualified_name;

Libraries/LibWeb/HTML/FormControlInfrastructure.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ WebIDL::ExceptionOr<Optional<Vector<XHR::FormDataEntry>>> construct_entry_list(J
189189
entry_list.append(TRY(create_entry(realm, name.to_string(), control_as_form_associated_element->value().to_utf8_but_should_be_ported_to_utf16())));
190190
}
191191

192-
// 11. If the element has a dirname attribute, and that attribute's value is not the empty string, then:
193-
if (auto attribute = control->get_attribute(HTML::AttributeNames::dirname); attribute.has_value() && !attribute.value().is_empty()) {
192+
// 11. If the element has a dirname attribute, that attribute's value is not the empty string, and the element is an auto-directionality form-associated element:
193+
if (auto attribute = control->get_attribute(HTML::AttributeNames::dirname); attribute.has_value() && !attribute.value().is_empty() && control->is_auto_directionality_form_associated_element()) {
194194
// 1. Let dirname be the value of the element's dirname attribute.
195-
String dirname = attribute.value();
195+
String const& dirname = attribute.value();
196196

197197
// 2. Let dir be the string "ltr" if the directionality of the element is 'ltr', and "rtl" otherwise (i.e., when the directionality of the element is 'rtl').
198198
String dir = MUST((control->directionality() == DOM::Element::Directionality::Ltr) ? String::from_utf8("ltr"sv) : String::from_utf8("rtl"sv));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Harness status: OK
2+
3+
Found 4 tests
4+
5+
4 Pass
6+
Pass Submit input element directionality to FormData, if dirname applies.
7+
Pass Submit textarea element directionality to FormData.
8+
Pass Submit input element directionality, if dirname applies.
9+
Pass Submit textarea element directionality.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset=utf-8>
5+
<title>Submitting element directionality: the dirname attribute</title>
6+
<link rel="author" title="Vincent Hilla" href="mailto:vhilla@mozilla.com">
7+
<link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute">
8+
<script src="../../../../resources/testharness.js"></script>
9+
<script src="../../../../resources/testharnessreport.js"></script>
10+
<script src="resources/dirname.js"></script>
11+
</head>
12+
<body>
13+
<div id="log"></div>
14+
<form action="resources/dirname-iframe.html" method=get target="iframe">
15+
<textarea name="textarea" dirname="textarea.dir"></textarea>
16+
<p><input id="btn-submit" type=submit name=submit dirname=submit.dir value=Submit></p>
17+
</form>
18+
<iframe name="iframe"></iframe>
19+
20+
<script>
21+
const types_applies = [
22+
"hidden", "text", "search", "tel", "url", "email", "password", "submit"
23+
];
24+
const types_not = [
25+
"date", "month", "week", "time", "datetime-local", "number", "range", "color", "checkbox",
26+
"radio", "file", "image", "reset", "button"
27+
];
28+
const types = [...types_applies, ...types_not];
29+
let form = document.querySelector("form");
30+
for (const type of types) {
31+
if (type === "submit") {
32+
continue;
33+
}
34+
let p = document.createElement("p");
35+
let lbl = document.createElement("label");
36+
let txt = document.createTextNode(type + ": ");
37+
let inp = document.createElement("input");
38+
inp.type = type;
39+
inp.name = type;
40+
inp.dirName = type + ".dir";
41+
inp.id = "testelement." + type
42+
lbl.appendChild(txt);
43+
lbl.appendChild(inp);
44+
p.appendChild(lbl);
45+
form.appendChild(p);
46+
}
47+
// Avoid continue in https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set:attr-fe-dirname
48+
document.getElementById("testelement.checkbox").checked = true;
49+
document.getElementById("testelement.radio").checked = true;
50+
51+
function assertInputSubmission(data) {
52+
for (const type of types_applies) {
53+
assert_equals(data.get(type + ".dir"), "ltr", "Submit ltr for input type=" + type);
54+
}
55+
for (const type of types_not) {
56+
assert_false(data.has(type + ".dir"), "Do not submit dir for input type=" + type);
57+
}
58+
}
59+
60+
const submitter = document.getElementById("btn-submit");
61+
const data = new FormData(form, submitter);
62+
test(function() {
63+
assertInputSubmission(data);
64+
}, "Submit input element directionality to FormData, if dirname applies.");
65+
test(function() {
66+
assert_equals(data.get("textarea.dir"), "ltr", "Submit ltr for textarea");
67+
}, "Submit textarea element directionality to FormData.");
68+
69+
submitter.click();
70+
const t_inp = async_test("Submit input element directionality, if dirname applies.");
71+
onIframeLoadedDone(t_inp, function(params) {
72+
assertInputSubmission(params);
73+
});
74+
const t_ta = async_test("Submit textarea element directionality.");
75+
onIframeLoadedDone(t_ta, function(params) {
76+
assert_equals(params.get("textarea.dir"), "ltr", "Submit ltr for textarea");
77+
});
78+
</script>
79+
</body>
80+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!DOCTYPE html>
2+
<meta charset=utf-8>
3+
<title>Submitting element directionality: the dirname attribute support</title>
4+
<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function onIframeLoadedDone(t, cb, selector="iframe") {
2+
const iframe = document.querySelector(selector);
3+
iframe.addEventListener("load", function() {
4+
// The initial about:blank load event can be fired before the form navigation occurs.
5+
// See https://github.com/whatwg/html/issues/490 for more information.
6+
if(iframe.contentWindow.location.href == "about:blank") { return; }
7+
8+
const params = new URLSearchParams(iframe.contentWindow.location.search);
9+
t.step(() => cb(params))
10+
t.done();
11+
});
12+
}

0 commit comments

Comments
 (0)