Bug Tracker

Ticket #2228 (new bug)

Opened 10 months ago

Last modified 10 months ago

env.js patch -- String fixes, support for title and href/src getters that produce absolute URIs

Reported by: mikesamuel Assigned to: joern
Type: bug Priority: minor
Milestone: 1.2.3 Component: qunit
Version: 1.2.2 Keywords:
Cc: Needs: Review

Description

Below is a patch that fixes a few problems with runtests/env.js

There are a number of places where java.lang.Strings are not converted to javascript Strings.

The document.title attribute does not work.

The href attribute does not work, and the src attribute does not return an absolute URI.

cheers, mike

Index: jqueryjs/runtest/env.js =================================================================== --- third_party/js/jqueryjs/runtest/env.js (revision) +++ third_party/js/jqueryjs/runtest/env.js (working copy) @@ -190,6 +190,10 @@

get innerHTML(){

return this.documentElement.outerHTML;

},

+ get title() { + var titleNode = this.getElementsByTagName("title")[0]; + return titleNode ? titleNode.innerHTML : ; + },

get defaultView(){

return {

@@ -314,10 +318,10 @@

DOMElement.prototype = extend( new DOMNode(), {

get nodeName(){

- return this.tagName.toUpperCase(); + return String(this.tagName.toUpperCase());

}, get tagName(){

- return this._dom.getTagName(); + return String(this._dom.getTagName());

}, toString: function(){

return "<" + this.tagName + (this.id ? "#" + this.id : "" ) + ">";

@@ -449,7 +453,16 @@

get value() { return this.getAttribute("value") ""; }, set value(val) { return this.setAttribute("value",val); },

- get src() { return this.getAttribute("src") ""; }, + get href() { + if (!this._dom.hasAttribute("href")) { return undefined; } + return resolveUri(this, this.getAttribute("href")); + }, + set href(val) { return this.setAttribute("href",val); }, + + get src() { + if (!this._dom.hasAttribute("src")) { return undefined; } + return resolveUri(this, this.getAttribute("src")); + },

set src(val) { return this.setAttribute("src",val); },

get id() { return this.getAttribute("id") ""; },

@@ -457,7 +470,7 @@

getAttribute: function(name){

return this._dom.hasAttribute(name) ?

- new String( this._dom.getAttribute(name) ) : + String( this._dom.getAttribute(name) ) :

null;

}, setAttribute: function(name,value){

@@ -550,6 +563,25 @@

return a;

}

+ /** + * Resolves a relative uri to an absolute one in the context of + * this document. + * This will resolve relative to any <base> or document.location + * as appropriate. + */ + function resolveUri(node, uri) { + var doc = node.ownerDocument; + var bases = doc.getElementsByTagName("base"); + var baseUri = null; + if ( bases.length && bases[0]._dom.hasAttribute("href") ) { + // Don't access "href" property to avoid inf. recursion + baseUri = bases[0].getAttribute("href"); + } else { + baseUri = String(doc.location); + } + return String((new java.net.URI(baseUri)).resolve(uri)); + } +

// Helper method for generating the right // DOM objects based upon the type

Attachments

patch (2.6 kB) - added by mikesamuel 10 months ago.
Patch

Change History

Changed 10 months ago by mikesamuel

Patch

Changed 10 months ago by mikesamuel

Attached the patch instead since the one I pasted into the ticket body was reformatted.

Note: See TracTickets for help on using tickets.