From ab2aeb6d97d18b64559220e2517a70d5dd22a1a3 Mon Sep 17 00:00:00 2001 From: Dmitry Kolupaev Date: Tue, 18 Feb 2020 18:43:19 +0300 Subject: [PATCH] Implement step 5.13 for dirname correctly --- components/script/dom/htmlformelement.rs | 43 +++++++++++------------ components/script/dom/htmlinputelement.rs | 4 +-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index b9be88c9a1f0..7003df0bd75a 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -951,17 +951,6 @@ impl HTMLFormElement { HTMLElementTypeId::HTMLInputElement => { let input = child.downcast::().unwrap(); data_set.append(&mut input.form_datums(submitter, encoding)); - - let input_element = child.downcast::().unwrap(); - let dirname: DOMString = input.DirName(); - if !dirname.is_empty() { - let directionality = DOMString::from(input_element.directionality()); - data_set.push(FormDatum { - ty: input.Type().clone(), - name: dirname.clone(), - value: FormDatumValue::String(directionality), - }); - } }, HTMLElementTypeId::HTMLButtonElement => { let button = child.downcast::().unwrap(); @@ -987,21 +976,31 @@ impl HTMLFormElement { value: FormDatumValue::String(textarea.Value()), }); } - - let area_element = child.downcast::().unwrap(); - let dirname: DOMString = textarea.DirName(); - if !dirname.is_empty() { - let directionality = DOMString::from(area_element.directionality()); - data_set.push(FormDatum { - ty: textarea.Type().clone(), - name: dirname.clone(), - value: FormDatumValue::String(directionality), - }); - } }, _ => (), } } + + // Step: 5.13. Add an entry if element has dirname attribute + // An element can only have a dirname attribute if it is a textarea element + // or an input element whose type attribute is in either the Text state or the Search state + let child_element = child.downcast::().unwrap(); + let input_matches = child_element + .downcast::() + .map(|input| { + input.input_type() == InputType::Text || input.input_type() == InputType::Search + }) + .unwrap_or(false); + let textarea_matches = child_element.is::(); + let dirname = child_element.get_string_attribute(&local_name!("dirname")); + if (input_matches || textarea_matches) && !dirname.is_empty() { + let dir = DOMString::from(child_element.directionality()); + data_set.push(FormDatum { + ty: DOMString::from("string"), + name: dirname.clone(), + value: FormDatumValue::String(dir), + }); + } } data_set } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 07e5059a6488..a5fefa095ae6 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -339,14 +339,14 @@ impl HTMLInputElement { } pub fn directionality_from_value(value: &str) -> String { - if HTMLInputElement::first_strong_character_is_rtl(value) { + if HTMLInputElement::is_first_strong_character_rtl(value) { "rtl".to_owned() } else { "ltr".to_owned() } } - fn first_strong_character_is_rtl(value: &str) -> bool { + fn is_first_strong_character_rtl(value: &str) -> bool { for ch in value.chars() { return match bidi_class(ch) { BidiClass::L => false,