Repository: servo/servo
File: components/script/dom/html/htmlformelement.rs (Rust)

Code before:

        // Step 8
        let mut form_data = match self.get_form_dataset(Some(submitter), Some(encoding), can_gc) {
            Some(form_data) => form_data,
            None => return,
        };

        // Step 9. If form cannot navigate, then return.
        if self.upcast::<Element>().cannot_navigate() {
            return;
        }

        // Step 10. Let method be the submitter element's method.
        let method = submitter.method();
        // Step 11. If method is dialog, then:
        // TODO

        // Step 12. Let action be the submitter element's action.
        let mut action = submitter.action();

        // Step 13. If action is the empty string, let action be the URL of the form document.
        if action.is_empty() {
            action = DOMString::from(base.as_str());
        }
        // Step 14. Let parsed action be the result of encoding-parsing a URL given action, relative to submitter's node document.
        let action_components = match base.join(&action.str()) {
            Ok(url) => url,
            // Step 15. If parsed action is failure, then return.
            Err(_) => return,
        };
        // Step 16. Let scheme be the scheme of parsed action.
        let scheme = action_components.scheme().to_owned();
        // Step 17. Let enctype be the submitter element's enctype.
        let enctype = submitter.enctype();

        // Step 19. If the submitter element is a submit button and it has a formtarget attribute,
        // then set formTarget to the formtarget attribute value.
        let form_target = if submitter.is_submit_button() && submitter.target() != DOMString::new()
        {
            Some(submitter.target())
        } else {
            // Step 18. Let formTarget be null.
            None
        };
        // Step 20. Let target be the result of getting an element's target given submitter's form owner and formTarget.
        let form_owner = submitter.form_owner();
        let form = form_owner.as_deref().unwrap_or(self);
        let target = get_element_target(form.upcast::<Element>(), form_target);

        // Step 21. Let noopener be the result of getting an element's noopener with form, parsed action, and target.
        let noopener = self.relations.get().get_element_noopener(target.as_ref());

Review comment (suggestion):
`join` does not run the "encoding-parsing a URL" steps. We could use `‎Document::encoding_parse_a_url` here instead. https://github.com/servo/servo/blob/b7afca1214e76024ca465c5dba1b07fc98a839c0/components/script/dom/document.rs#L3301

Code after:

        // Step 8
        let mut form_data = match self.get_form_dataset(Some(submitter), Some(encoding), can_gc) {
            Some(form_data) => form_data,
            None => return,
        };

        // Step 9. If form cannot navigate, then return.
        if self.upcast::<Element>().cannot_navigate() {
            return;
        }

        // Step 10. Let method be the submitter element's method.
        let method = submitter.method();
        // Step 11. If method is dialog, then:
        // TODO

        // Step 12. Let action be the submitter element's action.
        let mut action = submitter.action();

        // Step 13. If action is the empty string, let action be the URL of the form document.
        if action.is_empty() {
            action = DOMString::from(base.as_str());
        }
        // Step 14. Let parsed action be the result of encoding-parsing a URL given action, relative to submitter's node document.
        let action_components = match base.join(&action.str()) {
            Ok(url) => url,
            // Step 15. If parsed action is failure, then return.
            Err(_) => return,
        };
        // Step 16. Let scheme be the scheme of parsed action.
        let scheme = action_components.scheme().to_owned();
        // Step 17. Let enctype be the submitter element's enctype.
        let enctype = submitter.enctype();

        // Step 19. If the submitter element is a submit button and it has a formtarget attribute,
        // then set formTarget to the formtarget attribute value.
        let form_target_attribute = submitter.target();
        let form_target = if submitter.is_submit_button() &&
            valid_navigable_target_name_or_keyword(&form_target_attribute)
        {
            Some(form_target_attribute)
        } else {
            // Step 18. Let formTarget be null.
            None
        };
        // Step 20. Let target be the result of getting an element's target given submitter's form owner and formTarget.
        let form_owner = submitter.form_owner();
        let form = form_owner.as_deref().unwrap_or(self);
        let target = get_element_target(form.upcast::<Element>(), form_target);