diff --git a/src/shell/shell.js b/src/shell/shell.js index 3a1f7e0..af9e928 100644 --- a/src/shell/shell.js +++ b/src/shell/shell.js @@ -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() { diff --git a/tests/spec/shell/wget.spec.js b/tests/spec/shell/wget.spec.js index 3608c8c..c2ab974 100644 --- a/tests/spec/shell/wget.spec.js +++ b/tests/spec/shell/wget.spec.js @@ -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;