Skip to content

Fixing filesystem paths in Envjs.uri #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
13 changes: 11 additions & 2 deletions specs/platform/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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 @@ -53,6 +53,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
4 changes: 2 additions & 2 deletions src/console/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/**
* @author envjs team
*/
var Console,
console;
/*var Console,
console;*/
4 changes: 2 additions & 2 deletions src/css/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* DOM Style Level 2
*/
var CSS2Properties,
/*var CSS2Properties,
CSSRule,
CSSStyleRule,
CSSImportRule,
Expand All @@ -13,4 +13,4 @@ var CSS2Properties,
CSSStyleSheet,
StyleSheet,
StyleSheetList;
;
;*/
4 changes: 2 additions & 2 deletions src/dom/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* be able to correctly implement to core browser DOM interfaces."
*/

var Attr,
/*var Attr,
CDATASection,
CharacterData,
Comment,
Expand All @@ -35,5 +35,5 @@ var Attr,
Range,
XMLSerializer,
DOMParser;

*/

4 changes: 2 additions & 2 deletions src/event/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* This file simply provides the global definitions we need to
* be able to correctly implement to core browser DOM Event interfaces.
*/
var Event,
/*var Event,
MouseEvent,
UIEvent,
KeyboardEvent,
Expand All @@ -17,4 +17,4 @@ var Event,
EventException,
//nonstandard but very useful for implementing mutation events
//among other things like general profiling
Aspect;
Aspect;*/
3 changes: 2 additions & 1 deletion src/html/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* This file simply provides the global definitions we need to
* be able to correctly implement to core browser DOM HTML interfaces.
*/
var HTMLDocument,
/*var HTMLDocument,
HTMLElement,
HTMLCollection,
HTMLAnchorElement,
Expand Down Expand Up @@ -64,3 +64,4 @@ var HTMLDocument,
Option,
__loadImage__,
__loadLink__;
*/
5 changes: 2 additions & 3 deletions src/parser/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//these are both non-standard globals that
//provide static namespaces and functions
//to support the html 5 parser from nu.
var XMLParser = {},
HTMLParser = {};

XMLParser = {};
HTMLParser = {};

6 changes: 6 additions & 0 deletions src/parser/htmldocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ var __elementPopped__ = function(ns, name, node){
doc.parsing = false;
//DOMContentLoaded event
try{
if ( Envjs.killTimersAfterLoad === true ) {
Envjs.clear();
}
if ( Envjs.fireLoad === false ) {
return;
}
if(doc.createEvent){
event = doc.createEvent('Events');
event.initEvent("DOMContentLoaded", false, false);
Expand Down
6 changes: 5 additions & 1 deletion src/platform/core/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright 2008-2010 John Resig, under the MIT License
*/

var Envjs = function(){
Envjs = function(){
var i,
name,
override = function(){
Expand All @@ -30,6 +30,10 @@ var Envjs = function(){
override(arguments[1]);
window.location = arguments[0];
}
if (Envjs.dontPrintUserAgent !== true && Envjs.printedUserAgent !== true) {
Envjs.printedUserAgent = true;
console.log('[ %s ]', window.navigator.userAgent);
}
return;
},
__this__ = this;
Expand Down
3 changes: 3 additions & 0 deletions src/platform/core/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Envjs.loadInlineScript = function(script){
'eval('+script.text.substring(0,16)+'...):'+new Date().getTime()
);
}
if ( Envjs.afterInlineScriptLoad ) {
Envjs.afterInlineScriptLoad(script)
}
//console.log('evaluated at scope %s \n%s',
// script.ownerDocument.ownerWindow.guid, script.text);
};
Expand Down
9 changes: 8 additions & 1 deletion src/platform/core/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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);

// Semi-common trick is to make an iframe with src='javascript:false'
Expand All @@ -27,6 +28,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 @@ -48,7 +55,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
2 changes: 1 addition & 1 deletion src/platform/rhino/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright 2008-2010 John Resig, under the MIT License
*/

var __context__ = Packages.org.mozilla.javascript.Context.getCurrentContext();
__context__ = Packages.org.mozilla.javascript.Context.getCurrentContext();

Envjs.platform = "Rhino";
Envjs.revision = "1.7.0.rc2";
4 changes: 2 additions & 2 deletions src/timer/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*
* requires Envjs.wait, Envjs.sleep, Envjs.WAIT_INTERVAL
*/
var setTimeout,
/*var setTimeout,
clearTimeout,
setInterval,
clearInterval;

*/


12 changes: 12 additions & 0 deletions src/timer/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ $timers.lock = function(fn){
Envjs.sync(fn)();
};

Envjs.clear = function(){
$timers.lock(function(){
for(var i=0; i<$timers.length; i++) {
if ( !$timers[i] ) {
continue;
}
$timers[i].stop();
delete $timers[i];
}
});
}

//private internal class
var Timer = function(fn, interval){
this.fn = fn;
Expand Down
4 changes: 2 additions & 2 deletions src/window/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/**
* @todo: document
*/
var Window,
/*var Window,
Screen,
History,
Navigator;

*/
3 changes: 1 addition & 2 deletions src/window/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,4 @@ Window = function(scope, parent, opener){

//finally pre-supply the window with the window-like environment
//console.log('Default Window');
new Window(__this__, __this__);
console.log('[ %s ]',window.navigator.userAgent);
new Window(__this__, __this__);
3 changes: 2 additions & 1 deletion src/xhr/__global__.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
* be able to correctly implement to core browser (XML)HTTPRequest
* interfaces.
*/
var Location,
/*var Location,
XMLHttpRequest;
*/