1
0
mirror of https://github.com/adobe/brackets.git synced 2024-11-20 09:53:00 +01:00

Use the core PathUtils and remove the external dependency

This commit is contained in:
ficristo 2015-09-23 21:54:28 +02:00
parent ab1581142f
commit 25b358050b
15 changed files with 989 additions and 193 deletions

3
.gitmodules vendored
View File

@ -1,9 +1,6 @@
[submodule "src/thirdparty/CodeMirror"]
path = src/thirdparty/CodeMirror
url = https://github.com/adobe/CodeMirror2.git
[submodule "src/thirdparty/path-utils"]
path = src/thirdparty/path-utils
url = https://github.com/jblas/path-utils.git
[submodule "src/thirdparty/mustache"]
path = src/thirdparty/mustache
url = https://github.com/janl/mustache.js.git

View File

@ -62,7 +62,6 @@
"define": false,
"brackets": false,
"$": false,
"PathUtils": false,
"window": false,
"navigator": false,
"Mustache": false

View File

@ -275,7 +275,6 @@ module.exports = function (grunt) {
'src/thirdparty/CodeMirror/addon/edit/closetag.js',
'src/thirdparty/CodeMirror/addon/selection/active-line.js',
'src/thirdparty/mustache/mustache.js',
'src/thirdparty/path-utils/path-utils.min',
'src/thirdparty/less-2.5.1.min.js'
],
helpers : [

View File

@ -23,7 +23,7 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*global define, $, PathUtils */
/*global define, $ */
/**
* CSSAgent keeps track of loaded style sheets and allows reloading them
@ -35,12 +35,11 @@
define(function CSSAgent(require, exports, module) {
"use strict";
require("thirdparty/path-utils/path-utils.min");
var _ = require("thirdparty/lodash");
var Inspector = require("LiveDevelopment/Inspector/Inspector"),
EventDispatcher = require("utils/EventDispatcher");
EventDispatcher = require("utils/EventDispatcher"),
PathUtils = require("utils/PathUtils");
/**
* Stylesheet details

View File

@ -39,7 +39,6 @@ define(function (require, exports, module) {
"use strict";
// Load dependent non-module scripts
require("thirdparty/path-utils/path-utils.min");
require("widgets/bootstrap-dropdown");
require("widgets/bootstrap-modal");
require("widgets/bootstrap-twipsy-mod");
@ -115,6 +114,18 @@ define(function (require, exports, module) {
}
});
// DEPRECATED: In future we want to remove the global CodeMirror, but for now we
// expose our required CodeMirror globally so as to avoid breaking extensions in the
// interim.
var PathUtils = require("utils/PathUtils");
Object.defineProperty(window, "PathUtils", {
get: function () {
DeprecationWarning.deprecationWarning('Use brackets.getModule("utils/PathUtils") instead of global PathUtils.', true);
return PathUtils;
}
});
// Load modules that self-register and just need to get included in the main project
require("command/DefaultMenus");
require("document/ChangedDocumentTracker");

View File

@ -24,7 +24,7 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define, $, brackets, PathUtils */
/*global define, $, brackets */
/**
* Functions for working with extension packages
@ -39,6 +39,7 @@ define(function (require, exports, module) {
Strings = require("strings"),
ExtensionLoader = require("utils/ExtensionLoader"),
NodeConnection = require("utils/NodeConnection"),
PathUtils = require("utils/PathUtils"),
PreferencesManager = require("preferences/PreferencesManager");
PreferencesManager.definePreference("proxy", "string", undefined, {

View File

@ -22,7 +22,7 @@
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window, PathUtils */
/*global define, brackets, $, window */
define(function (require, exports, module) {
"use strict";
@ -39,6 +39,7 @@ define(function (require, exports, module) {
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
LanguageManager = brackets.getModule("language/LanguageManager"),
Strings = brackets.getModule("strings"),
PathUtils = brackets.getModule("utils/PathUtils"),
ViewUtils = brackets.getModule("utils/ViewUtils"),
TokenUtils = brackets.getModule("utils/TokenUtils");

View File

@ -21,7 +21,7 @@
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window */
/*global define, brackets, $ */
define(function (require, exports, module) {
@ -36,6 +36,7 @@ define(function (require, exports, module) {
HTMLUtils = brackets.getModule("language/HTMLUtils"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
ProjectManager = brackets.getModule("project/ProjectManager"),
PathUtils = brackets.getModule("utils/PathUtils"),
StringUtils = brackets.getModule("utils/StringUtils"),
Strings = brackets.getModule("strings"),
Data = require("text!data.json"),
@ -80,7 +81,7 @@ define(function (require, exports, module) {
docDir = FileUtils.getDirectoryPath(doc.file.fullPath);
// get relative path from query string
queryUrl = window.PathUtils.parseUrl(query.queryStr);
queryUrl = PathUtils.parseUrl(query.queryStr);
if (queryUrl) {
queryDir = queryUrl.directory;
}

View File

@ -23,7 +23,7 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, PathUtils, Mustache */
/*global define, Mustache */
/**
* PreferencesDialogs
@ -31,11 +31,10 @@
*/
define(function (require, exports, module) {
"use strict";
require("thirdparty/path-utils/path-utils.min");
var Dialogs = require("widgets/Dialogs"),
ProjectManager = require("project/ProjectManager"),
PathUtils = require("utils/PathUtils"),
StringUtils = require("utils/StringUtils"),
Strings = require("strings"),
SettingsDialogTemplate = require("text!htmlContent/project-settings-dialog.html");

@ -1 +0,0 @@
Subproject commit 08dba4f8724edeede95660dbd90d8ad2ad13640d

View File

@ -23,7 +23,7 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, less, PathUtils */
/*global define, $, brackets, less */
/**
* ExtensionUtils defines utility methods for implementing extensions.
@ -32,6 +32,7 @@ define(function (require, exports, module) {
"use strict";
var Async = require("utils/Async"),
PathUtils = require("utils/PathUtils"),
FileSystem = require("filesystem/FileSystem"),
FileUtils = require("file/FileUtils");

View File

@ -28,204 +28,207 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(function( window ){
/*jslint regexp: true*/
/*globals define*/
var PathUtils = {
// This scary looking regular expression parses an absolute URL or its relative
// variants (protocol, site, document, query, and hash), into the various
// components (protocol, host, path, query, fragment, etc that make up the
// URL as well as some other commonly used sub-parts. When used with RegExp.exec()
// or String.match, it parses the URL into a results array that looks like this:
//
// [0]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content
// [1]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread
// [2]: http://jblas:password@mycompany.com:8080/mail/inbox
// [3]: http://jblas:password@mycompany.com:8080
// [4]: http:
// [5]: //
// [6]: jblas:password@mycompany.com:8080
// [7]: jblas:password
// [8]: jblas
// [9]: password
// [10]: mycompany.com:8080
// [11]: mycompany.com
// [12]: 8080
// [13]: /mail/inbox
// [14]: /mail/
// [15]: inbox
// [16]: ?msg=1234&type=unread
// [17]: #msg-content
//
urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#\.]*(?:\.[^\?#\.]+)*(\.[^\?#\.]+)|[^\?#]*)))?(\?[^#]+)?)(#.*)?/,
define(function (require, exports, module) {
"use strict";
// These are the property names we set on the parsed url object. The order of the names
// in this array must match the order of the sub-matches in urlParseRE!
parsedUrlPropNames: [
"href",
"hrefNoHash",
"hrefNoSearch",
"domain",
"protocol",
"doubleSlash",
"authority",
"userinfo",
"username",
"password",
"host",
"hostname",
"port",
"pathname",
"directory",
"filename",
"filenameExtension",
"search",
"hash"
],
var PathUtils = {
// This scary looking regular expression parses an absolute URL or its relative
// variants (protocol, site, document, query, and hash), into the various
// components (protocol, host, path, query, fragment, etc that make up the
// URL as well as some other commonly used sub-parts. When used with RegExp.exec()
// or String.match, it parses the URL into a results array that looks like this:
//
// [0]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content
// [1]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread
// [2]: http://jblas:password@mycompany.com:8080/mail/inbox
// [3]: http://jblas:password@mycompany.com:8080
// [4]: http:
// [5]: //
// [6]: jblas:password@mycompany.com:8080
// [7]: jblas:password
// [8]: jblas
// [9]: password
// [10]: mycompany.com:8080
// [11]: mycompany.com
// [12]: 8080
// [13]: /mail/inbox
// [14]: /mail/
// [15]: inbox
// [16]: ?msg=1234&type=unread
// [17]: #msg-content
//
urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#\.]*(?:\.[^\?#\.]+)*(\.[^\?#\.]+)|[^\?#]*)))?(\?[^#]+)?)(#.*)?/,
defaultPorts: { http: "80", https: "443", ftp: "20", ftps: "990" },
// These are the property names we set on the parsed url object. The order of the names
// in this array must match the order of the sub-matches in urlParseRE!
parsedUrlPropNames: [
"href",
"hrefNoHash",
"hrefNoSearch",
"domain",
"protocol",
"doubleSlash",
"authority",
"userinfo",
"username",
"password",
"host",
"hostname",
"port",
"pathname",
"directory",
"filename",
"filenameExtension",
"search",
"hash"
],
parseUrl: function( url ) {
defaultPorts: { http: "80", https: "443", ftp: "20", ftps: "990" },
// If we're passed an object, we'll assume that it is
// a parsed url object and just return it back to the caller.
if ( url && typeof url === "object" ) {
return url;
}
parseUrl: function (url) {
var matches = PathUtils.urlParseRE.exec( url || "" ) || [],
props = PathUtils.parsedUrlPropNames,
cnt = props.length,
result = {},
i;
for ( i = 0; i < cnt; i++ ) {
// Most browsers returns an empty string for empty sub-matches, but
// IE returns undefined, so we need to make sure we normalize empty
// sub-matches so results are consistent across all browsers.
result[ props[ i ] ] = matches[ i ] || "";
}
// If we're passed an object, we'll assume that it is
// a parsed url object and just return it back to the caller.
if (url && typeof url === "object") {
return url;
}
return result;
},
var matches = PathUtils.urlParseRE.exec(url || "") || [],
props = PathUtils.parsedUrlPropNames,
cnt = props.length,
result = {},
i;
port: function( url ) {
var u = PathUtils.parseUrl( url );
return u.port || PathUtils.defaultPorts[u.protocol];
},
for (i = 0; i < cnt; i++) {
// Most browsers returns an empty string for empty sub-matches, but
// IE returns undefined, so we need to make sure we normalize empty
// sub-matches so results are consistent across all browsers.
isSameDomain: function( absUrl1, absUrl2 ) {
return PathUtils.parseUrl( absUrl1 ).domain === PathUtils.parseUrl( absUrl2 ).domain;
},
result[props[i]] = matches[i] || "";
}
//Returns true for any relative variant.
isRelativeUrl: function( url ) {
// All relative Url variants have one thing in common, no protocol.
return PathUtils.parseUrl( url ).protocol === "";
},
return result;
},
//Returns true for an absolute url.
isAbsoluteUrl: function( url ) {
return PathUtils.parseUrl( url ).protocol !== "";
},
port: function (url) {
var u = PathUtils.parseUrl(url);
return u.port || PathUtils.defaultPorts[u.protocol];
},
// Turn relPath into an asbolute path. absPath is
// an optional absolute path which describes what
// relPath is relative to.
isSameDomain: function (absUrl1, absUrl2) {
return PathUtils.parseUrl(absUrl1).domain === PathUtils.parseUrl(absUrl2).domain;
},
makePathAbsolute: function( relPath, absPath ) {
if ( relPath && relPath.charAt( 0 ) === "/" ) {
return relPath;
}
//Returns true for any relative variant.
isRelativeUrl: function (url) {
// All relative Url variants have one thing in common, no protocol.
return PathUtils.parseUrl(url).protocol === "";
},
relPath = relPath || "";
absPath = absPath ? absPath.replace( /^\/|(\/[^\/]*|[^\/]+)$/g, "" ) : "";
//Returns true for an absolute url.
isAbsoluteUrl: function (url) {
return PathUtils.parseUrl(url).protocol !== "";
},
var absStack = absPath ? absPath.split( "/" ) : [],
relStack = relPath.split( "/" );
for ( var i = 0; i < relStack.length; i++ ) {
var d = relStack[ i ];
switch ( d ) {
case ".":
break;
case "..":
if ( absStack.length ) {
absStack.pop();
}
break;
default:
absStack.push( d );
break;
}
}
return "/" + absStack.join( "/" );
},
// Turn relPath into an asbolute path. absPath is
// an optional absolute path which describes what
// relPath is relative to.
// Turn absolute pathA into a path that is
// relative to absolute pathB.
makePathAbsolute: function (relPath, absPath) {
if (relPath && relPath.charAt(0) === "/") {
return relPath;
}
makePathRelative: function( pathA, pathB ) {
// Remove any file reference in the path.
pathB = pathB ? pathB.replace( /^\/|\/?[^\/]*$/g, "" ) : "";
pathA = pathA ? pathA.replace( /^\//, "" ) : "";
relPath = relPath || "";
absPath = absPath ? absPath.replace(/^\/|(\/[^\/]*|[^\/]+)$/g, "") : "";
var stackB = pathB ? pathB.split( "/" ) : [],
stackA = pathA.split( "/" ),
stackC = [],
len = stackB.length,
upLevel = false,
startIndex = 0;
var absStack = absPath ? absPath.split("/") : [],
relStack = relPath.split("/"),
i;
for (i = 0; i < relStack.length; i++) {
var d = relStack[i];
switch (d) {
case ".":
break;
case "..":
if (absStack.length) {
absStack.pop();
}
break;
default:
absStack.push(d);
break;
}
}
return "/" + absStack.join("/");
},
for ( var i = 0; i < len; i++ ) {
upLevel = upLevel || stackA[ 0 ] !== stackB[ i ];
if ( upLevel ) {
stackC.push( ".." );
} else {
stackA.shift();
}
}
return stackC.concat( stackA ).join( "/" );
},
// Turn absolute pathA into a path that is
// relative to absolute pathB.
// Turn any relative URL variant into an absolute URL.
makePathRelative: function (pathA, pathB) {
// Remove any file reference in the path.
pathB = pathB ? pathB.replace(/^\/|\/?[^\/]*$/g, "") : "";
pathA = pathA ? pathA.replace(/^\//, "") : "";
makeUrlAbsolute: function( relUrl, absUrl ) {
if ( !PathUtils.isRelativeUrl( relUrl ) ) {
return relUrl;
}
var stackB = pathB ? pathB.split("/") : [],
stackA = pathA.split("/"),
stackC = [],
len = stackB.length,
upLevel = false,
i;
var relObj = PathUtils.parseUrl( relUrl ),
absObj = PathUtils.parseUrl( absUrl ),
protocol = relObj.protocol || absObj.protocol,
doubleSlash = relObj.protocol ? relObj.doubleSlash : ( relObj.doubleSlash || absObj.doubleSlash ),
authority = relObj.authority || absObj.authority,
hasPath = relObj.pathname !== "",
pathname = PathUtils.makePathAbsolute( relObj.pathname || absObj.filename, absObj.pathname ),
search = relObj.search || ( !hasPath && absObj.search ) || "",
hash = relObj.hash;
for (i = 0; i < len; i++) {
upLevel = upLevel || stackA[0] !== stackB[i];
if (upLevel) {
stackC.push("..");
} else {
stackA.shift();
}
}
return stackC.concat(stackA).join("/");
},
return protocol + doubleSlash + authority + pathname + search + hash;
}
};
// Turn any relative URL variant into an absolute URL.
// For every parsedUrlPropName, make sure there is a getter function defined on the PathUtils object.
makeUrlAbsolute: function (relUrl, absUrl) {
if (!PathUtils.isRelativeUrl(relUrl)) {
return relUrl;
}
function getterFunc( propName )
{
return function( url ){
return PathUtils.parseUrl( url )[ propName ];
}
}
var relObj = PathUtils.parseUrl(relUrl),
absObj = PathUtils.parseUrl(absUrl),
protocol = relObj.protocol || absObj.protocol,
doubleSlash = relObj.protocol ? relObj.doubleSlash : (relObj.doubleSlash || absObj.doubleSlash),
authority = relObj.authority || absObj.authority,
hasPath = relObj.pathname !== "",
pathname = PathUtils.makePathAbsolute(relObj.pathname || absObj.filename, absObj.pathname),
search = relObj.search || (!hasPath && absObj.search) || "",
hash = relObj.hash;
var i, prop, props = PathUtils.parsedUrlPropNames, cnt = props.length;
for ( i = 0; i < cnt; i++ ) {
prop = props[ i ];
if ( !PathUtils[ prop ] ) {
PathUtils[ prop ] = getterFunc( prop );
}
}
return protocol + doubleSlash + authority + pathname + search + hash;
}
};
// Expose PathUtils to the world.
window.PathUtils = PathUtils;
// For every parsedUrlPropName, make sure there is a getter function defined on the PathUtils object.
})( window );
function getterFunc(propName) {
return function (url) {
return PathUtils.parseUrl(url)[propName];
};
}
var i, prop, props = PathUtils.parsedUrlPropNames, cnt = props.length;
for (i = 0; i < cnt; i++) {
prop = props[i];
if (!PathUtils[prop]) {
PathUtils[prop] = getterFunc(prop);
}
}
// Expose PathUtils to the world.
module.exports = exports = PathUtils;
});

View File

@ -37,7 +37,6 @@
<!-- Keep in sync with Gruntfile.js jasmine vendor dependencies -->
<script src="../src/thirdparty/jquery-2.1.3.min.js"></script>
<script src="../src/thirdparty/mustache/mustache.js"></script>
<script src="../src/thirdparty/path-utils/path-utils.js"></script>
<script src="../src/thirdparty/less-2.5.1.min.js"></script>
<script src="thirdparty/bootstrap2/js/bootstrap.min.js"></script>

View File

@ -73,6 +73,7 @@ define(function (require, exports, module) {
require("spec/NativeMenu-test");
require("spec/NodeConnection-test");
require("spec/Pane-test");
require("spec/PathUtils-test");
require("spec/PreferencesBase-test");
require("spec/PreferencesManager-test");
require("spec/ProjectManager-test");

786
test/spec/PathUtils-test.js Normal file
View File

@ -0,0 +1,786 @@
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*global define, describe, it, expect */
define(function (require, exports, module) {
"use strict";
var PathUtils = require("utils/PathUtils");
var testParseUrls = [
"http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
"/mail/inbox?msg=1234&type=unread#msg-content",
"mail/inbox?msg=1234&type=unread#msg-content",
"inbox?msg=1234&type=unread#msg-content",
"?msg=1234&type=unread#msg-content",
"#msg-content",
"http://mycompany.com/mail/inbox?msg=1234&type=unread#msg-content",
"//mycompany.com/mail/inbox?msg=1234&type=unread#msg-content",
"/mail/inbox?msg=1234&type=unread#msg-content",
"mail/inbox?msg=1234&type=unread#msg-content",
"inbox?msg=1234&type=unread#msg-content",
"http://jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
"http://mycompany.com/a/b.php?foo=1&bar=2",
"http://mycompany.com/b.php?foo=1&bar=2",
"http://mycompany.com/a/b.html",
"http://mycompany.com/b.html",
"a/file.html",
"/file.html",
"file.html",
"../file.html",
"a/b/../../file.html",
"http://mycompany.com/a/b-1.0-min.js?foo=1&bar=2"
];
var testParseResults = [
{
href: "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "http://jblas:password@mycompany.com:8080/mail/inbox",
domain: "http://jblas:password@mycompany.com:8080",
protocol: "http:",
doubleSlash: "//",
authority: "jblas:password@mycompany.com:8080",
userinfo: "jblas:password",
username: "jblas",
password: "password",
host: "mycompany.com:8080",
hostname: "mycompany.com",
port: "8080",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "//jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "//jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "//jblas:password@mycompany.com:8080/mail/inbox",
domain: "//jblas:password@mycompany.com:8080",
protocol: "",
doubleSlash: "//",
authority: "jblas:password@mycompany.com:8080",
userinfo: "jblas:password",
username: "jblas",
password: "password",
host: "mycompany.com:8080",
hostname: "mycompany.com",
port: "8080",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content"
},
{
href: "//mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "//mycompany.com:8080/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "//mycompany.com:8080/mail/inbox",
domain: "//mycompany.com:8080",
protocol: "",
doubleSlash: "//",
authority: "mycompany.com:8080",
userinfo: "",
username: "",
password: "",
host: "mycompany.com:8080",
hostname: "mycompany.com",
port: "8080",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content"
},
{
href: "/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "/mail/inbox",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content"
},
{
href: "mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "mail/inbox?msg=1234&type=unread",
hrefNoSearch: "mail/inbox",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "mail/inbox",
directory: "mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content"
},
{
href: "inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "inbox?msg=1234&type=unread",
hrefNoSearch: "inbox",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "inbox",
directory: "",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content"
},
{
href: "?msg=1234&type=unread#msg-content",
hrefNoHash: "?msg=1234&type=unread",
hrefNoSearch: "",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "",
directory: "",
filename: "",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "#msg-content",
hrefNoHash: "",
hrefNoSearch: "",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "",
directory: "",
filename: "",
filenameExtension: "",
search: "",
hash: "#msg-content",
},
{
href: "http://mycompany.com/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "http://mycompany.com/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "http://mycompany.com/mail/inbox",
domain: "http://mycompany.com",
protocol: "http:",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "//mycompany.com/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "//mycompany.com/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "//mycompany.com/mail/inbox",
domain: "//mycompany.com",
protocol: "",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "/mail/inbox",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "mail/inbox?msg=1234&type=unread",
hrefNoSearch: "mail/inbox",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "mail/inbox",
directory: "mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "inbox?msg=1234&type=unread",
hrefNoSearch: "inbox",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "inbox",
directory: "",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "http://jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "http://jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "http://jblas:password@123.456.78.9:8080/mail/inbox",
domain: "http://jblas:password@123.456.78.9:8080",
protocol: "http:",
doubleSlash: "//",
authority: "jblas:password@123.456.78.9:8080",
userinfo: "jblas:password",
username: "jblas",
password: "password",
host: "123.456.78.9:8080",
hostname: "123.456.78.9",
port: "8080",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "//jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "//jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "//jblas:password@123.456.78.9:8080/mail/inbox",
domain: "//jblas:password@123.456.78.9:8080",
protocol: "",
doubleSlash: "//",
authority: "jblas:password@123.456.78.9:8080",
userinfo: "jblas:password",
username: "jblas",
password: "password",
host: "123.456.78.9:8080",
hostname: "123.456.78.9",
port: "8080",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "//123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
hrefNoHash: "//123.456.78.9:8080/mail/inbox?msg=1234&type=unread",
hrefNoSearch: "//123.456.78.9:8080/mail/inbox",
domain: "//123.456.78.9:8080",
protocol: "",
doubleSlash: "//",
authority: "123.456.78.9:8080",
userinfo: "",
username: "",
password: "",
host: "123.456.78.9:8080",
hostname: "123.456.78.9",
port: "8080",
pathname: "/mail/inbox",
directory: "/mail/",
filename: "inbox",
filenameExtension: "",
search: "?msg=1234&type=unread",
hash: "#msg-content",
},
{
href: "http://mycompany.com/a/b.php?foo=1&bar=2",
hrefNoHash: "http://mycompany.com/a/b.php?foo=1&bar=2",
hrefNoSearch: "http://mycompany.com/a/b.php",
domain: "http://mycompany.com",
protocol: "http:",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/a/b.php",
directory: "/a/",
filename: "b.php",
filenameExtension: ".php",
search: "?foo=1&bar=2",
hash: "",
},
{
href: "http://mycompany.com/b.php?foo=1&bar=2",
hrefNoHash: "http://mycompany.com/b.php?foo=1&bar=2",
hrefNoSearch: "http://mycompany.com/b.php",
domain: "http://mycompany.com",
protocol: "http:",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/b.php",
directory: "/",
filename: "b.php",
filenameExtension: ".php",
search: "?foo=1&bar=2",
hash: "",
},
{
href: "http://mycompany.com/a/b.html",
hrefNoHash: "http://mycompany.com/a/b.html",
hrefNoSearch: "http://mycompany.com/a/b.html",
domain: "http://mycompany.com",
protocol: "http:",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/a/b.html",
directory: "/a/",
filename: "b.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "http://mycompany.com/b.html",
hrefNoHash: "http://mycompany.com/b.html",
hrefNoSearch: "http://mycompany.com/b.html",
domain: "http://mycompany.com",
protocol: "http:",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/b.html",
directory: "/",
filename: "b.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "a/file.html",
hrefNoHash: "a/file.html",
hrefNoSearch: "a/file.html",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "a/file.html",
directory: "a/",
filename: "file.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "/file.html",
hrefNoHash: "/file.html",
hrefNoSearch: "/file.html",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "/file.html",
directory: "/",
filename: "file.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "file.html",
hrefNoHash: "file.html",
hrefNoSearch: "file.html",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "file.html",
directory: "",
filename: "file.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "../file.html",
hrefNoHash: "../file.html",
hrefNoSearch: "../file.html",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "../file.html",
directory: "../",
filename: "file.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "a/b/../../file.html",
hrefNoHash: "a/b/../../file.html",
hrefNoSearch: "a/b/../../file.html",
domain: "",
protocol: "",
doubleSlash: "",
authority: "",
userinfo: "",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "a/b/../../file.html",
directory: "a/b/../../",
filename: "file.html",
filenameExtension: ".html",
search: "",
hash: "",
},
{
href: "http://mycompany.com/a/b-1.0-min.js?foo=1&bar=2",
hrefNoHash: "http://mycompany.com/a/b-1.0-min.js?foo=1&bar=2",
hrefNoSearch: "http://mycompany.com/a/b-1.0-min.js",
domain: "http://mycompany.com",
protocol: "http:",
doubleSlash: "//",
authority: "mycompany.com",
userinfo: "",
username: "",
password: "",
host: "mycompany.com",
hostname: "mycompany.com",
port: "",
pathname: "/a/b-1.0-min.js",
directory: "/a/",
filename: "b-1.0-min.js",
filenameExtension: ".js",
search: "?foo=1&bar=2",
hash: "",
}
];
var testPaths = [
{
base: "",
relative: "foo.html"
},
{
base: "/",
relative: "foo.html"
},
{
base: "/file",
relative: "foo.html"
},
{
base: "/dir/",
relative: "foo.html"
},
{
base: "/",
relative: "../foo.html"
},
{
base: "/file",
relative: "../foo.html"
},
{
base: "/dir/",
relative: "../foo.html"
},
{
base: "/a/b/",
relative: "../foo.html"
},
{
base: "/a/b/",
relative: "./.././foo.html" //9
},
{
base: "/a/b/",
relative: "../../foo.html"
},
{
base: "/a/b/",
relative: "../../../../../../../../foo.html"
},
{
base: "/a/b/",
relative: "../../c/d/"
},
{
base: "/a/b/c/d/e/f/g/file.html",
relative: "../../h/i/j/k/l/m/n/"
},
{
base: "/a/b/c/d/e/f/g/file.html",
relative: "../../h/i/j/k/l/m/n/bar.html"
},
{
base: "/a/b/c/d/e/f/g/",
relative: "../../h/i/j/k/l/m/n/"
},
{
base: "/a/b/c/d/e/f/g/",
relative: "../../../../../../../h/i/j/k/l/m/n/bar.html"
},
{
base: "/a/b/c/d/e/f/g/",
relative: "../../../../../../../h/i/j/k/l/m/n/"
},
];
var testPathResults = [
{
abs: "/foo.html",
rel: "foo.html"
},
{
abs: "/foo.html",
rel: "foo.html"
},
{
abs: "/foo.html",
rel: "foo.html"
},
{
abs: "/dir/foo.html",
rel: "foo.html"
},
{
abs: "/foo.html",
rel: "foo.html"
},
{
abs: "/foo.html",
rel: "foo.html"
},
{
abs: "/foo.html",
rel: "../foo.html"
},
{
abs: "/a/foo.html",
rel: "../foo.html"
},
{
abs: "/a/foo.html",
rel: "../foo.html"
},
{
abs: "/foo.html",
rel: "../../foo.html"
},
{
abs: "/foo.html",
rel: "../../foo.html"
},
{
abs: "/c/d/",
rel: "../../c/d/"
},
{
abs: "/a/b/c/d/e/h/i/j/k/l/m/n/",
rel: "../../h/i/j/k/l/m/n/"
},
{
abs: "/a/b/c/d/e/h/i/j/k/l/m/n/bar.html",
rel: "../../h/i/j/k/l/m/n/bar.html"
},
{
abs: "/a/b/c/d/e/h/i/j/k/l/m/n/",
rel: "../../h/i/j/k/l/m/n/"
},
{
abs: "/h/i/j/k/l/m/n/bar.html",
rel: "../../../../../../../h/i/j/k/l/m/n/bar.html"
},
{
abs: "/h/i/j/k/l/m/n/",
rel: "../../../../../../../h/i/j/k/l/m/n/",
}
];
var props = PathUtils.parsedUrlPropNames;
describe("PathUtils", function () {
describe("Parse Urls Tests", function () {
testParseUrls.forEach(function (url, index) {
it("should parse the url " + url + " correctly", function () {
var obj = PathUtils.parseUrl(url),
expectedResults = testParseResults[index];
props.forEach(function (prop) {
expect(obj[prop]).toBe(expectedResults[prop]);
});
});
});
});
describe("Make Absolute Tests", function () {
testPaths.forEach(function (item, index) {
it("Use 'base' (" + item.base + ") to turn 'relative' (" + item.relative + ") into an absolute path.", function () {
var absPath = PathUtils.makePathAbsolute(item.relative, item.base);
expect(absPath).toBe(testPathResults[index].abs);
});
});
});
describe("Make Relative Tests", function () {
testPaths.forEach(function (item, index) {
it("Make 'B' (" + testPathResults[index].abs + ") a path that is relative to 'A' (" + item.base + ").", function () {
var relPath = PathUtils.makePathRelative(testPathResults[index].abs, item.base);
expect(relPath).toBe(testPathResults[index].rel);
});
});
});
});
});