express-negotiator
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -90,5 +90,8 @@ var fs = require('fs'), | ||
if (extensionString) { | ||
extensionString.split(/(?=\.)/).forEach(function (extension) { | ||
var extensionWithoutLeadingDot = extension.substr(1), | ||
localeId = normalizeLocaleId(extensionWithoutLeadingDot); | ||
variantInfo.extensionsWithoutLeadingDot = extensionString.split(/(?=\.)/).map(function (extensionWithLeadingDot) { | ||
return extensionWithLeadingDot.substr(1); | ||
}); | ||
variantInfo.unmatchedExtensionsWithoutLeadingDot = []; | ||
variantInfo.extensionsWithoutLeadingDot.forEach(function (extensionWithoutLeadingDot) { | ||
var localeId = normalizeLocaleId(extensionWithoutLeadingDot); | ||
if (isLocaleIdRegExp.test(localeId)) { | ||
@@ -105,2 +108,3 @@ variantInfo.localeId = localeId; | ||
variantInfo.allExtensionsMatched = false; | ||
variantInfo.unmatchedExtensionsWithoutLeadingDot.push(extensionWithoutLeadingDot); | ||
} | ||
@@ -240,3 +244,4 @@ } | ||
bestVariantInfo, | ||
bestVariantQuality; | ||
bestVariantQuality, | ||
bestVariantNumAdditionalExtensionsMatched; | ||
if (variantInfos) { | ||
@@ -250,3 +255,16 @@ for (var i = 0 ; i < prioritizedLocaleIds.length ; i += 1) { | ||
return next(); | ||
} else if (variantInfo.allExtensionsMatched) { | ||
} else { | ||
var numAdditionalExtensionsMatched = 0, | ||
allExtensionsMatched = variantInfo.allExtensionsMatched; | ||
if (!allExtensionsMatched) { | ||
var extensionsWithoutLeadingDot = extensionString.replace(/^\./, '').split('.'); | ||
if (extensionsWithoutLeadingDot.every(function (extensionWithoutLeadingDot) { | ||
return variantInfo.unmatchedExtensionsWithoutLeadingDot.indexOf(extensionWithoutLeadingDot) !== -1; | ||
})) { | ||
allExtensionsMatched = true; | ||
numAdditionalExtensionsMatched = extensionsWithoutLeadingDot.length; | ||
} else { | ||
continue; | ||
} | ||
} | ||
if (!variantInfo.localeId || localeIdsEqual(variantInfo.localeId, localeId)) { | ||
@@ -296,2 +314,3 @@ var contentTypeQuality = 0; | ||
(contentTypeQuality === bestVariantQuality && bestVariantInfo.contentType !== 'text/html' && variantInfo.contentType === 'text/html') || | ||
numAdditionalExtensionsMatched > bestVariantNumAdditionalExtensionsMatched || | ||
// Make sure that a strict locale id match takes precedence over an alias (in case eg. both nb and no versions are available): | ||
@@ -302,2 +321,3 @@ bestVariantInfo && bestVariantInfo.localeId !== localeId && variantInfo.localeId === localeId) { | ||
bestVariantQuality = contentTypeQuality; | ||
bestVariantNumAdditionalExtensionsMatched = numAdditionalExtensionsMatched; | ||
} | ||
@@ -304,0 +324,0 @@ } |
@@ -25,3 +25,3 @@ { | ||
], | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"engines": { | ||
@@ -28,0 +28,0 @@ "node": "*" |
@@ -83,2 +83,4 @@ var Path = require('path'), | ||
createTest('a non-locale id and non-mario extension in the request url should be honored, and if a variant has it, it should be preferred', {url: '/index.nocdn', headers: {accept: '*/html'}}, '/index.nocdn.en_US.html'); | ||
// no and nb should be considered aliases: | ||
@@ -85,0 +87,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39607
43
464