Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-negotiator

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-negotiator - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

test/root/index.nocdn.en_US.html

30

lib/expressNegotiator.js

@@ -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 @@ }

2

package.json

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc