Skip to content

Commit

Permalink
Correctly reflection formEl.action
Browse files Browse the repository at this point in the history
Now it resolves the URL correctly, and returns the document's URL if the attribute is absent or empty.

Closes #1482.
  • Loading branch information
domenic committed May 15, 2016
1 parent e955ac7 commit 499944e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 57 deletions.
14 changes: 14 additions & 0 deletions lib/jsdom/living/nodes/HTMLFormElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const mapper = require("../../utils").mapper;
const domSymbolTree = require("../helpers/internal-constants").domSymbolTree;
const createHTMLCollection = require("../../living/html-collection").create;
const notImplemented = require("../../browser/not-implemented");
const resourceLoader = require("../../browser/resource-loader");

// http://www.whatwg.org/specs/web-apps/current-work/#category-listed
const listedElements = /button|fieldset|input|keygen|object|select|textarea/i;
Expand Down Expand Up @@ -107,6 +108,19 @@ class HTMLFormElementImpl extends HTMLElementImpl {
set enctype(V) {
this.setAttribute("enctype", V);
}

get action() {
const attributeValue = this.getAttribute("action");
if (attributeValue === null || attributeValue === "") {
return this._ownerDocument.URL;
}

return resourceLoader.resolveResourceUrl(this._ownerDocument, attributeValue);
}

set action(V) {
this.setAttribute("action", V);
}
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion lib/jsdom/living/nodes/HTMLFormElement.idl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[OverrideBuiltins]
interface HTMLFormElement : HTMLElement {
[Reflect=accept_charset] attribute DOMString acceptCharset;
[Reflect] attribute DOMString action;
attribute DOMString action;
// attribute DOMString autocomplete;
attribute DOMString enctype;
// attribute DOMString encoding;
Expand Down
56 changes: 0 additions & 56 deletions test/level2/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6794,33 +6794,6 @@ exports.tests = {
test.done();
},

/**
*
The action attribute specifies the server-side form handler.
Retrieve the action attribute and examine its value.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-74049184
*/
HTMLFormElement05: function(test) {
var success;
var nodeList;
var testNode;
var vaction;
var doc;
var docRef = null;
if (typeof(this.doc) != 'undefined') {
docRef = this.doc;
}
doc = load("form");
nodeList = doc.getElementsByTagName("form");
test.equal(nodeList.length, 1, 'Asize');
testNode = nodeList.item(0);
vaction = testNode.action;
test.equal(vaction, './files/getData.pl', 'actionLink');
test.done();
},

/**
*
The enctype attribute specifies the content of the submitted form.
Expand Down Expand Up @@ -17324,35 +17297,6 @@ exports.tests = {
test.done();
},

/**
*
The value of attribute action of the form element which contains this button is read and checked against the expected value
* @author Netscape
* @author Sivakiran Tummala
* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-71254493
* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-74049184
*/
button03: function(test) {
var success;
var nodeList;
var testNode;
var formNode;
var vfaction;
var doc;
var docRef = null;
if (typeof(this.doc) != 'undefined') {
docRef = this.doc;
}
doc = load("button");
nodeList = doc.getElementsByTagName("button");
test.equal(nodeList.length, 2, 'Asize');
testNode = nodeList.item(0);
formNode = testNode.form;
vfaction = formNode.action;
test.equal(vfaction, "...", "formLink");
test.done();
},

/**
*
The value of attribute method of the form element which contains this button is read and checked against the expected value
Expand Down
1 change: 1 addition & 0 deletions test/web-platform-tests/to-upstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("Local tests in Web Platform Test format (to-upstream)", () => {
"domparsing/insert-adjacent.html",
"html/dom/elements/elements-in-the-dom/click-in-progress-flag.html",
"html/editing/focus/focus-management/active-element.html",
"html/semantics/forms/the-form-element/form-action.html",
"html/semantics/forms/the-input-element/checkbox-click-events.html",
"html/semantics/forms/the-input-element/disabled-checkbox.html",
"html/semantics/forms/the-input-element/radio-input-cancel.html",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>form.action</title>
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<form id="form1" action="a.html"></form>

<form id="form2" action=""></form>

<form id="form3"></form>

<body>
<script>
"use strict";

test(() => {

assert_equals(document.querySelector("#form1").action, (new URL("a.html", document.URL)).href,
"action should equal the correct absolute URL");

}, "An action URL should be resolved relative to the document's URL");

test(() => {

assert_equals(document.querySelector("#form2").action, document.URL);

}, "An empty-string action content attribute should cause the IDL attribute to return the document's URL");

test(() => {

assert_equals(document.querySelector("#form3").action, document.URL);

}, "A missing action content attribute should cause the IDL attribute to return the document's URL");

</script>
</body>

0 comments on commit 499944e

Please sign in to comment.