Skip to content

Commit

Permalink
handle degenerate URL case
Browse files Browse the repository at this point in the history
  • Loading branch information
client9 committed Apr 6, 2010
1 parent aa9e7b1 commit 1d25222
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
10 changes: 8 additions & 2 deletions src/platform/core/xhr.js
@@ -1,11 +1,11 @@

/**
* getcwd - named after posix call of same name (see 'man 2 getcwd')
*
*
*/
Envjs.getcwd = function() {
return '.';
}
};

/**
* resolves location relative to doc location
Expand All @@ -27,6 +27,12 @@ Envjs.uri = function(path, base) {
return urlparse.urlnormalize(path);
}

// interesting special case, a few very large websites use
// '//foo/bar/' to mean 'http://foo/bar'
if (path.match('^//')) {
path = 'http:' + path;
}

// if base not passed in, try to get it from document
// Ideally I would like the caller to pass in document.baseURI to
// make this more self-sufficient and testable
Expand Down
83 changes: 44 additions & 39 deletions test/specs/platform/rhino.js
Expand Up @@ -11,39 +11,39 @@ load('settings.js');
module('rhino');

test('Envjs Platform Interfaces Available', function(){

ok(Envjs, 'Envjs defined');
ok(Envjs.log.toString() !== 'function(){};', 'Envjs.log defined');
ok(Envjs.proxy.toString() !== 'function(){};', 'Envjs.proxy defined');

});

var document = null,
path = 'specs/env/spec.html';
path = 'specs/env/spec.html';

test('Envjs.uri', function(){
var uri;

uri = Envjs.uri('specs/env/spec.html', 'http://envjs.com/abc123/');
ok(uri, 'Able to create uri');
equals(uri, 'http://envjs.com/abc123/'+path, 'uri');
equals(uri.toString(), 'http://envjs.com/abc123/'+path, 'uri');

document = {baseURI:'http://envjs.com/'};

uri = Envjs.uri('specs/env/spec.html');
ok(uri, 'Able to create uri');
equals(uri, 'http://envjs.com/specs/env/spec.html', 'uri');
equals(uri.toString(), 'http://envjs.com/specs/env/spec.html', 'uri');


uri = Envjs.uri('specs/env/spec.html', 'http://envjs.com/');
ok(uri, 'Able to create uri');
equals(uri, 'http://envjs.com/specs/env/spec.html', 'uri');
equals(uri.toString(), 'http://envjs.com/specs/env/spec.html', 'uri');

document = null;

uri = Envjs.uri('http://envjs.com/specs/env/spec.html');
ok(uri, 'Able to create uri');
equals(uri, 'http://envjs.com/specs/env/spec.html', 'uri');
Expand Down Expand Up @@ -84,6 +84,11 @@ test('Envjs.uri', function(){
uri = Envjs.uri('https://foo.com/bar/');
equals(uri, 'https://foo.com/bar/', 'https, absolute, with path, with ending "/"');

// weird degenerate case. Starting with double slash implies HTTP
// not a file URL. Used on Very Large websites.
uri = Envjs.uri('//foo.com/bar');
equals(uri, 'http://foo.com/bar', 'degenerate url case');

// make sure whatever is parsing this doesn't choke on ip address
// or localhost
uri = Envjs.uri('http://127.0.0.1/');
Expand Down Expand Up @@ -150,7 +155,7 @@ test('Envjs.uri', function(){
//Foo is a minimal window implementation
var Foo = function(scope, parent){
var $proxy = new Envjs.proxy(scope, parent),
$parent = parent;
$parent = parent;
scope.__proxy__ = $proxy;
return __extend__(scope,{
get parent(){
Expand All @@ -169,51 +174,51 @@ var Foo = function(scope, parent){
}
});
};

var _this = this;

test('Envjs.proxy', function(){

var frame = {},
subframe = {};
var frame = {},
subframe = {};

new Foo(_this, _this);
equals(abcdefghi.parent, abcdefghi, '.parent');
equals(abcdefghi.top, abcdefghi, '.top');

new Foo(frame, abcdefghi);
equals(frame.parent, abcdefghi, '.parent');

new Foo(subframe, frame);
equals(subframe.parent, frame, '.parent');
equals(subframe.parent.parent, abcdefghi, '.parent.parent');
equals(subframe.top, abcdefghi, '.top');


});

/*test('qunit same', function(){
var top = {owner:null, parent:null, children:[], type:1};
var a = {owner:top, parent:top, children:[], type:2};
var b = {owner:top, parent:top, children:[], type:2};
var c = {owner:top, parent:a, children:[], type:3};
var d = {owner:top, parent:b, children:[], type:4};
top.children.push(a, b);
a.children.push(c);
b.children.push(d);
//prevent jsDump stack overflow
QUnit.jsDump.parse=function(thing){return thing+'';};
//this will cause its own overflow
same(a, b, 'will this ever return?');
//This will cause a stack overflow
//QUnit.jsDump.parse(a);
});*/
var top = {owner:null, parent:null, children:[], type:1};
var a = {owner:top, parent:top, children:[], type:2};
var b = {owner:top, parent:top, children:[], type:2};
var c = {owner:top, parent:a, children:[], type:3};
var d = {owner:top, parent:b, children:[], type:4};
top.children.push(a, b);
a.children.push(c);
b.children.push(d);
//prevent jsDump stack overflow
QUnit.jsDump.parse=function(thing){return thing+'';};
//this will cause its own overflow
same(a, b, 'will this ever return?');
//This will cause a stack overflow
//QUnit.jsDump.parse(a);
});*/

Envjs.onExit(function(){
console.log('onExit!');
Expand Down

0 comments on commit 1d25222

Please sign in to comment.