Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add response.url parameter and give jsdom proper URLs #49

Merged
merged 1 commit into from

2 participants

@jhurliman

If jsdom is not given an options.url property, it will default to using the current script filename as the URL. This messes with the automatic path resolution in jQuery and causes the following code:

$('a[href]').each(function(i, a) { console.log(a.href); }

To print URLs like:

/home/ubuntu/myapp/node_modules/node.io/lib/node.io/relative/web/path/

To fix this, I added a url property to the response object which parseHtml() passes into the jsdom() method.

@jhurliman jhurliman Adds a url parameter to the response object and passes the URL into j…
…sdom to avoid setting the jQuery document URL to __dirname
94b9426
@chriso
Owner

Thanks!

@chriso chriso merged commit f39a4fb into chriso:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 18, 2011
  1. @jhurliman

    Adds a url parameter to the response object and passes the URL into j…

    jhurliman authored
    …sdom to avoid setting the jQuery document URL to __dirname
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 1 deletion.
  1. +1 −1  lib/node.io/dom.js
  2. +2 −0  lib/node.io/request.js
View
2  lib/node.io/dom.js
@@ -52,7 +52,7 @@ Job.prototype.parseHtml = function (data, callback, response) {
};
var $, window, jquery, default_$;
try {
- window = require('jsdom').jsdom(data, null, {features:features}).createWindow();
+ window = require('jsdom').jsdom(data, null, {features:features, url:response.url}).createWindow();
jquery = require('jquery');
default_$ = jquery.create(window);
$ = function (selector, context) {
View
2  lib/node.io/request.js
@@ -311,6 +311,8 @@ Job.prototype.doRequest = function (method, resource, body, headers, callback, p
request = (secure ? https : http).request(options, function (response) {
+ response.url = resource;
+
request_reponse = response;
if (self.is_complete) {
Something went wrong with that request. Please try again.