Bug Tracker

Modify

Ticket #2228 (closed bug: invalid)

Opened 5 years ago

Last modified 4 years ago

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

Reported by: mikesamuel Owned by: joern
Priority: minor Milestone: 1.2.3
Component: qunit Version: 1.2.2
Keywords: Cc:
Blocking: Blocked by:

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 Download (2.6 KB) - added by mikesamuel 5 years ago.
Patch

Change History

Changed 5 years ago by mikesamuel

Patch

comment:1 Changed 5 years ago by mikesamuel

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

comment:2 Changed 4 years ago by joern

  • Status changed from new to closed
  • Resolution set to invalid

The env.js group would probably a good place to post this:  http://groups.google.com/group/envjs

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.