diff --git a/src/shell/shell.js b/src/shell/shell.js index af9e928..4d33c01 100644 --- a/src/shell/shell.js +++ b/src/shell/shell.js @@ -441,15 +441,10 @@ define(function(require) { 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 - // remove any non-filename type chars. - var filename = url.replace(/\?.*$/, ''); - filename = filename.replace(/\#.*$/, ''); - filename = filename.split('/').pop(); - return filename.replace(/[^a-zA-Z0-9-_\.\~]/, ''); - }()); + // Grab whatever is after the last / (assuming there is one) and + // remove any non-filename type chars(i.e., : and /). Like the real + // wget, we leave query string or hash portions in tact. + var path = options.filename || url.replace(/[:/]/g, '').split('/').pop(); 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 c2ab974..078c04a 100644 --- a/tests/spec/shell/wget.spec.js +++ b/tests/spec/shell/wget.spec.js @@ -60,7 +60,6 @@ define(["Filer", "util"], function(Filer, util) { shell.wget(url, { filename: 'test-file.txt' }, function(err, path) { if(err) throw err; - // The filename should be something like /file-13424512341 expect(path).to.equal('/test-file.txt'); 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(); + }); + }); + }); + + }); });