Skip to main content

Bug Tracker

Side navigation

#2228 closed bug (invalid)

Opened January 23, 2008 11:13PM UTC

Closed June 10, 2009 09:01AM UTC

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:
Blocked by: Blocking:
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 (1)
  • patch (2.6 KB) - added by mikesamuel January 23, 2008 11:14PM UTC.

    Patch

Change History (2)

Changed January 23, 2008 11:16PM UTC by mikesamuel comment:1

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

Changed June 10, 2009 09:01AM UTC by joern comment:2

resolution: → invalid
status: newclosed

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