Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/debug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -cp rhino/js.jar org.mozilla.javascript.tools.debugger.Main envjs/rhino.js %*
1 change: 1 addition & 0 deletions bin/envjs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -Xmx512M -jar rhino/js.jar -opt -1 envjs/rhino.js %*
20 changes: 15 additions & 5 deletions envjs/platform/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2763,6 +2763,7 @@ Envjs.getcwd = function() {
* @param {Object} base (semi-optional) The base url used in resolving "path" above
*/
Envjs.uri = function(path, base) {
path = path.replace(/\\/g, '/');
//console.log('constructing uri from path %s and base %s', path, base);
path = path+'';
// Semi-common trick is to make an iframe with src='javascript:false'
Expand All @@ -2777,6 +2778,12 @@ Envjs.uri = function(path, base) {
return urlparse.urlnormalize(path);
}

// if path is a Windows style absolute path (C:\foo\bar\index.html)
// make it a file: URL
if (path.match('^[a-zA-Z]+:/')) {
return 'file:///' + urlparse.urlnormalize(path);
}

// interesting special case, a few very large websites use
// '//foo/bar/' to mean 'http://foo/bar'
if (path.match('^//')) {
Expand All @@ -2798,7 +2805,7 @@ Envjs.uri = function(path, base) {
// if base is still empty, then we are in QA mode loading local
// files. Get current working directory
if (!base) {
base = 'file://' + Envjs.getcwd() + '/';
base = 'file:///' + (""+Envjs.getcwd()).replace(/\\/g, '/') + '/';
}
// handles all cases if path is abosulte or relative to base
// 3rd arg is "false" --> remove fragments
Expand Down Expand Up @@ -2884,13 +2891,15 @@ Envjs.localXHR = function(url, xhr, connection, data){
xhr.statusText = "ok";
xhr.responseText = Envjs.readFromFile(url);
try{
if(url.match(/html$/)){
//url as passed in here might be an object, so stringify it
var urlstring = url.toString();
if(urlstring.match(/html$/)){
xhr.responseHeaders["Content-Type"] = 'text/html';
}else if(url.match(/.xml$/)){
}else if(urlstring.match(/.xml$/)){
xhr.responseHeaders["Content-Type"] = 'text/xml';
}else if(url.match(/.js$/)){
}else if(urlstring.match(/.js$/)){
xhr.responseHeaders["Content-Type"] = 'text/javascript';
}else if(url.match(/.json$/)){
}else if(urlstring.match(/.json$/)){
xhr.responseHeaders["Content-Type"] = 'application/json';
}else{
xhr.responseHeaders["Content-Type"] = 'text/plain';
Expand All @@ -2914,6 +2923,7 @@ Envjs.localXHR = function(url, xhr, connection, data){
__extend__(Envjs, urlparse);

}(/*Envjs.XMLHttpRequest.Core*/));

(function(){

var log = Envjs.logger('Envjs.Window');
Expand Down
13 changes: 11 additions & 2 deletions specs/platform/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ test('Envjs.uri', function(){
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;
document = null;

uri = Envjs.uri('http://envjs.com/specs/env/spec.html');
ok(uri, 'Able to create uri');
Expand All @@ -59,6 +59,15 @@ test('Envjs.uri', function(){

uri = Envjs.uri('file:///foo/bar/');
equals(uri, 'file:///foo/bar/', 'File, absolute, with ending "/"');

// handle windows style file paths, firefox will convert this to a file: URL
uri = Envjs.uri('C:\\foo\\bar\\index.html');
equals(uri, 'file:///C:/foo/bar/index.html', 'File, absolute, converted slashes');

// when there is no document and you pass a relative path, it should be converted to a file: URL
document = null;
uri = Envjs.uri('specs/env/spec.html');
ok(/file\:\/\/\/.*\/specs\/env\/spec.html/.test(uri), 'Relative filesystem paths work');

uri = Envjs.uri('http://foo.com');
equals(uri, 'http://foo.com/', 'http, absolute, without path, without ending "/"');
Expand Down
21 changes: 15 additions & 6 deletions src/platform/core/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Envjs.getcwd = function() {
* @param {Object} base (semi-optional) The base url used in resolving "path" above
*/
Envjs.uri = function(path, base) {
path = path.replace(/\\/g, '/');
//console.log('constructing uri from path %s and base %s', path, base);
path = path+'';
// Semi-common trick is to make an iframe with src='javascript:false'
Expand All @@ -37,6 +38,12 @@ Envjs.uri = function(path, base) {
return urlparse.urlnormalize(path);
}

// if path is a Windows style absolute path (C:\foo\bar\index.html)
// make it a file: URL
if (path.match('^[a-zA-Z]+:/')) {
return 'file:///' + urlparse.urlnormalize(path);
}

// interesting special case, a few very large websites use
// '//foo/bar/' to mean 'http://foo/bar'
if (path.match('^//')) {
Expand All @@ -58,7 +65,7 @@ Envjs.uri = function(path, base) {
// if base is still empty, then we are in QA mode loading local
// files. Get current working directory
if (!base) {
base = 'file://' + Envjs.getcwd() + '/';
base = 'file:///' + (""+Envjs.getcwd()).replace(/\\/g, '/') + '/';
}
// handles all cases if path is abosulte or relative to base
// 3rd arg is "false" --> remove fragments
Expand Down Expand Up @@ -144,13 +151,15 @@ Envjs.localXHR = function(url, xhr, connection, data){
xhr.statusText = "ok";
xhr.responseText = Envjs.readFromFile(url);
try{
if(url.match(/html$/)){
//url as passed in here might be an object, so stringify it
var urlstring = url.toString();
if(urlstring.match(/html$/)){
xhr.responseHeaders["Content-Type"] = 'text/html';
}else if(url.match(/.xml$/)){
}else if(urlstring.match(/.xml$/)){
xhr.responseHeaders["Content-Type"] = 'text/xml';
}else if(url.match(/.js$/)){
}else if(urlstring.match(/.js$/)){
xhr.responseHeaders["Content-Type"] = 'text/javascript';
}else if(url.match(/.json$/)){
}else if(urlstring.match(/.json$/)){
xhr.responseHeaders["Content-Type"] = 'application/json';
}else{
xhr.responseHeaders["Content-Type"] = 'text/plain';
Expand All @@ -173,4 +182,4 @@ Envjs.localXHR = function(url, xhr, connection, data){

__extend__(Envjs, urlparse);

}(/*Envjs.XMLHttpRequest.Core*/));
}(/*Envjs.XMLHttpRequest.Core*/));