mirror of
https://github.com/bower/bower.git
synced 2026-02-11 14:34:58 -05:00
Finish UrlResolver tests, fix some bugs.
This commit is contained in:
@@ -45,7 +45,8 @@ UrlResolver.prototype._hasNew = function (pkgMeta) {
|
||||
// Make an HEAD request to the source
|
||||
return Q.nfcall(request.head, this._source, {
|
||||
proxy: this._config.proxy,
|
||||
timeout: 5000
|
||||
timeout: 5000,
|
||||
headers: reqHeaders
|
||||
})
|
||||
// Compare new headers with the old ones
|
||||
.spread(function (response) {
|
||||
@@ -133,7 +134,7 @@ UrlResolver.prototype._download = function () {
|
||||
UrlResolver.prototype._parseHeaders = function (file, response) {
|
||||
var disposition,
|
||||
newFile,
|
||||
matches;
|
||||
match;
|
||||
|
||||
// Check if we got a Content-Disposition header
|
||||
disposition = response.headers['content-disposition'];
|
||||
@@ -141,19 +142,29 @@ UrlResolver.prototype._parseHeaders = function (file, response) {
|
||||
return Q.resolve([file, response]);
|
||||
}
|
||||
|
||||
// If so, extract the filename from it
|
||||
// Since there's various security issues with parsing this header,
|
||||
// we only interpret word chars plus dots, dashes and spaces
|
||||
// Also the filename can't start with a space and end with a
|
||||
// dot or a space (this is known to cause issues in Windows)
|
||||
// Since there's various security issues with parsing this header, we only
|
||||
// interpret word chars plus dots, dashes and spaces
|
||||
match = disposition.match(/filename=(?:"([\w\-\. ]+)")/i);
|
||||
if (!match) {
|
||||
// The spec defines that the filename must be in quotes,
|
||||
// though a wide range of servers do not follow the rule
|
||||
match = disposition.match(/filename=([\w\-\.]+)/i);
|
||||
if (!match) {
|
||||
return Q.resolve([file, response]);
|
||||
}
|
||||
}
|
||||
|
||||
// Trim spaces
|
||||
newFile = match[1].trim();
|
||||
|
||||
// The filename can't end with a dot because this is known
|
||||
// cause issues in Windows
|
||||
// See: http://superuser.com/questions/230385/dots-at-end-of-file-name
|
||||
matches = disposition.match(/filename="?([\w\.\-](?:[\w\.\- ]*[\w\-]))"?/i);
|
||||
if (!matches) {
|
||||
if (mout.string.endsWith(newFile, '.')) {
|
||||
return Q.resolve([file, response]);
|
||||
}
|
||||
|
||||
// Rename our downloaded file
|
||||
newFile = path.join(this._tempDir, matches[1]);
|
||||
newFile = path.join(this._tempDir, newFile);
|
||||
|
||||
return Q.nfcall(fs.rename, file, newFile)
|
||||
.then(function () {
|
||||
|
||||
@@ -74,6 +74,10 @@ function extractGz(archive, dest) {
|
||||
}
|
||||
|
||||
function getExtractor(archive) {
|
||||
// Make the archive lower case to match against the types
|
||||
// This ensures that upper-cased extensions work
|
||||
archive = archive.toLowerCase();
|
||||
|
||||
var type = mout.array.find(extractorTypes, function (type) {
|
||||
return mout.string.endsWith(archive, type);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user