kopia lustrzana https://github.com/c9/core
fix path normalization
rodzic
cc31762d57
commit
1283f57730
|
@ -72,7 +72,7 @@
|
|||
"c9.ide.find": "#6cc6d3379d",
|
||||
"c9.ide.find.infiles": "#72582de3cd",
|
||||
"c9.ide.find.replace": "#e4daf722b8",
|
||||
"c9.ide.run.debug": "#23a188b91a",
|
||||
"c9.ide.run.debug": "#0526107587",
|
||||
"c9.automate": "#47e2c429c9",
|
||||
"c9.ide.ace.emmet": "#0ab4c6cd68",
|
||||
"c9.ide.ace.gotoline": "#4d1a93172c",
|
||||
|
|
|
@ -275,9 +275,37 @@ define(function(require, exports, module) {
|
|||
+ md5Email + "?s=" + size + "&d=" + (defaultImage || "retro");
|
||||
};
|
||||
|
||||
var reHome = new RegExp("^" + plugin.escapeRegExp(c9.home || "/home/ubuntu"));
|
||||
var reHome, reWorkspace, homeSub;
|
||||
plugin.$initPaths = function(home, workspaceDir) {
|
||||
reHome = new RegExp("^" + plugin.escapeRegExp(home) + "(/|/?$)");
|
||||
var wd = workspaceDir.replace(/\/?$/, "");
|
||||
reWorkspace = new RegExp("^" + plugin.escapeRegExp(wd) + "(/|/?$)");
|
||||
homeSub = "~/";
|
||||
if (home == workspaceDir) {
|
||||
reHome = new RegExp("^(" + plugin.escapeRegExp(home) + "|~)(/|/?$)");
|
||||
homeSub = "/";
|
||||
reWorkspace = null;
|
||||
} else if (reHome.test(workspaceDir)) {
|
||||
reWorkspace = new RegExp("^" +
|
||||
plugin.escapeRegExp(workspaceDir.replace(reHome, "~/")) + "(/|/?$)"
|
||||
);
|
||||
} else if (reWorkspace.test(home)) {
|
||||
reHome = new RegExp("^(" + plugin.escapeRegExp(home) + "|~)(/|/?$)");
|
||||
homeSub = home.replace(reWorkspace, "/").replace(/\/?$/, "/");
|
||||
reWorkspace = null;
|
||||
}
|
||||
};
|
||||
plugin.$initPaths(c9.home || "/home/ubuntu", c9.workspaceDir || "/");
|
||||
|
||||
plugin.normalizePath = function(path){
|
||||
return path && normalize(path.replace(reHome, "~"));
|
||||
if (!path) return "";
|
||||
if (reHome) {
|
||||
path = path.replace(reHome, homeSub);
|
||||
if (reWorkspace) {
|
||||
path = path.replace(reWorkspace, "/");
|
||||
}
|
||||
}
|
||||
return normalize(path);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
"use client";
|
||||
|
||||
|
||||
require(["lib/architect/architect", "lib/chai/chai"], function (architect, chai) {
|
||||
var expect = chai.expect;
|
||||
|
||||
|
@ -35,6 +36,41 @@ require(["lib/architect/architect", "lib/chai/chai"], function (architect, chai)
|
|||
});
|
||||
});
|
||||
|
||||
describe('normalizePath', function() {
|
||||
var normalizePath = util.normalizePath;
|
||||
it('should handle home in workspaceDir', function() {
|
||||
util.$initPaths("/home/ubuntu", "/");
|
||||
expect(normalizePath("/home/ubuntu")).to.equal("/home/ubuntu/");
|
||||
expect(normalizePath("/home/ubuntu/x")).to.equal("/home/ubuntu/x");
|
||||
expect(normalizePath("/home/ubuntu/x/y")).to.equal("/home/ubuntu/x/y");
|
||||
expect(normalizePath("/home/ubuntu/xy")).to.equal("/home/ubuntu/xy");
|
||||
expect(normalizePath("/")).to.equal("/");
|
||||
expect(normalizePath("~/z")).to.equal("/home/ubuntu/z");
|
||||
});
|
||||
it('should handle workspaceDir in home', function() {
|
||||
util.$initPaths("/home/ubuntu", "/home/ubuntu/x");
|
||||
expect(normalizePath("/home/ubuntu")).to.equal("~/");
|
||||
expect(normalizePath("/home/ubuntu/x")).to.equal("/");
|
||||
expect(normalizePath("/home/ubuntu/x/y")).to.equal("/y");
|
||||
expect(normalizePath("/home/ubuntu/xy")).to.equal("~/xy");
|
||||
expect(normalizePath("/")).to.equal("/");
|
||||
expect(normalizePath("~/z")).to.equal("~/z");
|
||||
});
|
||||
it('should handle home == workspaceDir', function() {
|
||||
util.$initPaths("/home/ubuntu", "/home/ubuntu");
|
||||
expect(normalizePath("/home/ubuntu")).to.equal("/");
|
||||
expect(normalizePath("/home/ubuntu/x")).to.equal("/x");
|
||||
expect(normalizePath("/home/ubuntu/x/y")).to.equal("/x/y");
|
||||
expect(normalizePath("/home/ubuntu/xy")).to.equal("/xy");
|
||||
expect(normalizePath("/")).to.equal("/");
|
||||
expect(normalizePath("~/z")).to.equal("/z");
|
||||
});
|
||||
it('should handle relative paths', function() {
|
||||
util.$initPaths("/home/ubuntu", "/");
|
||||
expect(normalizePath("/home/ubuntu/x/y/.//../z")).to.equal("/home/ubuntu/x/z");
|
||||
});
|
||||
});
|
||||
|
||||
onload && onload();
|
||||
}
|
||||
});
|
Ładowanie…
Reference in New Issue