Bug 1178609 - fix join in add-on SDK loader to work with resource:/// (uplifted from addon-sdk) r=zer0

This commit is contained in:
James Long 2015-08-13 12:48:52 -04:00
parent 404415fbee
commit 6b5cd4f293
2 changed files with 14 additions and 8 deletions

View File

@ -194,14 +194,16 @@ function readURI(uri) {
// Combines all arguments into a resolved, normalized path
function join (...paths) {
let resolved = normalize(pathJoin(...paths))
// OS.File `normalize` strips out the second slash in
// `resource://` or `chrome://`, and third slash in
// `file:///`, so we work around this
resolved = resolved.replace(/^resource\:\/([^\/])/, 'resource://$1');
resolved = resolved.replace(/^file\:\/([^\/])/, 'file:///$1');
resolved = resolved.replace(/^chrome\:\/([^\/])/, 'chrome://$1');
return resolved;
let joined = pathJoin(...paths);
let resolved = normalize(joined);
// OS.File `normalize` strips out any additional slashes breaking URIs like
// `resource://`, `resource:///`, `chrome://` or `file:///`, so we work
// around this putting back the slashes originally given, for such schemes.
let re = /^(resource|file|chrome)(\:\/{1,3})([^\/])/;
let matches = joined.match(re);
return resolved.replace(re, (...args) => args[1] + matches[2] + args[3]);
}
Loader.join = join;

View File

@ -57,6 +57,10 @@ exports['test join'] = function (assert) {
'resource://my/path/yeah/whoa');
assert.equal(join('resource://my/path/yeah/yuh', './whoa'),
'resource://my/path/yeah/yuh/whoa');
assert.equal(join('resource:///my/path/yeah/yuh', '../whoa'),
'resource:///my/path/yeah/whoa');
assert.equal(join('resource:///my/path/yeah/yuh', './whoa'),
'resource:///my/path/yeah/yuh/whoa');
assert.equal(join('file:///my/path/yeah/yuh', '../whoa'),
'file:///my/path/yeah/whoa');
assert.equal(join('file:///my/path/yeah/yuh', './whoa'),