Improve automatic filename extraction for wget
This commit is contained in:
parent
3e11408f44
commit
9725f0a412
|
@ -441,7 +441,15 @@ define(function(require) {
|
|||
return;
|
||||
}
|
||||
|
||||
var path = options.filename || ('file-' + Date.now());
|
||||
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
|
||||
// remove any non-filename type chars.
|
||||
var filename = url.replace(/\?.*$/, '');
|
||||
filename = filename.replace(/\#.*$/, '');
|
||||
filename = filename.split('/').pop();
|
||||
return filename.replace(/[^a-zA-Z0-9-_\.\~]/, '');
|
||||
}());
|
||||
path = Path.resolve(fs.cwd, path);
|
||||
|
||||
function onerror() {
|
||||
|
|
|
@ -40,8 +40,7 @@ define(["Filer", "util"], function(Filer, util) {
|
|||
shell.wget(url, function(err, path) {
|
||||
if(err) throw err;
|
||||
|
||||
// The filename should be something like /file-13424512341
|
||||
expect(path).to.match(/^\/file\-\d+$/);
|
||||
expect(path).to.equal('/test-file.txt');
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if(err) throw err;
|
||||
|
|
Loading…
Reference in New Issue