Allow query string and hashes in wget filenames and add tests.
This commit is contained in:
parent
670b84eba9
commit
1b12f44a02
|
@ -441,15 +441,10 @@ define(function(require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = options.filename || (function() {
|
|
||||||
// Strip any query string or hash portions of the url first, then
|
|
||||||
// Grab whatever is after the last / (assuming there is one) and
|
// Grab whatever is after the last / (assuming there is one) and
|
||||||
// remove any non-filename type chars.
|
// remove any non-filename type chars(i.e., : and /). Like the real
|
||||||
var filename = url.replace(/\?.*$/, '');
|
// wget, we leave query string or hash portions in tact.
|
||||||
filename = filename.replace(/\#.*$/, '');
|
var path = options.filename || url.replace(/[:/]/g, '').split('/').pop();
|
||||||
filename = filename.split('/').pop();
|
|
||||||
return filename.replace(/[^a-zA-Z0-9-_\.\~]/, '');
|
|
||||||
}());
|
|
||||||
path = Path.resolve(fs.cwd, path);
|
path = Path.resolve(fs.cwd, path);
|
||||||
|
|
||||||
function onerror() {
|
function onerror() {
|
||||||
|
|
|
@ -60,7 +60,6 @@ define(["Filer", "util"], function(Filer, util) {
|
||||||
shell.wget(url, { filename: 'test-file.txt' }, function(err, path) {
|
shell.wget(url, { filename: 'test-file.txt' }, function(err, path) {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
// The filename should be something like /file-13424512341
|
|
||||||
expect(path).to.equal('/test-file.txt');
|
expect(path).to.equal('/test-file.txt');
|
||||||
|
|
||||||
fs.readFile(path, 'utf8', function(err, data) {
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
|
@ -72,5 +71,46 @@ define(["Filer", "util"], function(Filer, util) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should download the contents of a file from a url with query string', function(done) {
|
||||||
|
var fs = util.fs();
|
||||||
|
var shell = fs.Shell();
|
||||||
|
var url = "test-file.txt?foo";
|
||||||
|
var contents = "This is a test file used in some of the tests.\n";
|
||||||
|
|
||||||
|
shell.wget(url, function(err, path) {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(path).to.equal('/test-file.txt?foo');
|
||||||
|
|
||||||
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(data).to.equal(contents);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should download the contents of a file from a url to specified filename, stripping : and /', function(done) {
|
||||||
|
var fs = util.fs();
|
||||||
|
var shell = fs.Shell();
|
||||||
|
var url = "test-file.txt?foo=:/";
|
||||||
|
var contents = "This is a test file used in some of the tests.\n";
|
||||||
|
|
||||||
|
shell.wget(url, function(err, path) {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(path).to.equal('/test-file.txt?foo=');
|
||||||
|
|
||||||
|
fs.readFile(path, 'utf8', function(err, data) {
|
||||||
|
if(err) throw err;
|
||||||
|
|
||||||
|
expect(data).to.equal(contents);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue