Socket
Socket
Sign inDemoInstall

find-my-way

Package Overview
Dependencies
4
Maintainers
2
Versions
107
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.4.0 to 5.4.1

22

lib/strategies/accept-host.js

@@ -5,15 +5,13 @@ 'use strict'

function HostStorage () {
var hosts = {}
var regexHosts = []
const hosts = {}
const regexHosts = []
return {
get: (host) => {
var exact = hosts[host]
const exact = hosts[host]
if (exact) {
return exact
}
var item
for (var i = 0; i < regexHosts.length; i++) {
item = regexHosts[i]
if (item.host.test(host)) {
return item.value
for (const regex of regexHosts) {
if (regex.host.test(host)) {
return regex.value
}

@@ -28,10 +26,2 @@ }

}
},
del: (host) => {
delete hosts[host]
regexHosts = regexHosts.filter((obj) => String(obj.host) !== String(host))
},
empty: () => {
hosts = {}
regexHosts = []
}

@@ -38,0 +28,0 @@ }

'use strict'
const SemVerStore = require('semver-store')
const assert = require('assert')
function SemVerStore () {
if (!(this instanceof SemVerStore)) {
return new SemVerStore()
}
this.store = {}
this.maxMajor = 0
this.maxMinors = {}
this.maxPatches = {}
}
SemVerStore.prototype.set = function (version, store) {
if (typeof version !== 'string') {
throw new TypeError('Version should be a string')
}
let [major, minor, patch] = version.split('.')
major = Number(major) || 0
minor = Number(minor) || 0
patch = Number(patch) || 0
if (major >= this.maxMajor) {
this.maxMajor = major
this.store.x = store
this.store['*'] = store
this.store['x.x'] = store
this.store['x.x.x'] = store
}
if (minor >= (this.maxMinors[major] || 0)) {
this.maxMinors[major] = minor
this.store[`${major}.x`] = store
this.store[`${major}.x.x`] = store
}
if (patch >= (this.store[`${major}.${minor}`] || 0)) {
this.maxPatches[`${major}.${minor}`] = patch
this.store[`${major}.${minor}.x`] = store
}
this.store[`${major}.${minor}.${patch}`] = store
return this
}
SemVerStore.prototype.get = function (version) {
return this.store[version]
}
module.exports = {

@@ -7,0 +55,0 @@ name: 'version',

{
"name": "find-my-way",
"version": "5.4.0",
"version": "5.4.1",
"description": "Crazy fast http radix based router",

@@ -48,4 +48,3 @@ "main": "index.js",

"fast-deep-equal": "^3.1.3",
"safe-regex2": "^2.0.0",
"semver-store": "^0.3.0"
"safe-regex2": "^2.0.0"
},

@@ -52,0 +51,0 @@ "tsd": {

@@ -164,5 +164,3 @@ # find-my-way

get: (type) => { return handlers[type] || null },
set: (type, store) => { handlers[type] = store },
del: (type) => { delete handlers[type] },
empty: () => { handlers = {} }
set: (type, store) => { handlers[type] = store }
}

@@ -209,5 +207,3 @@ },

get: (version) => { return versions[version] || null },
set: (version, store) => { versions[version] = store },
del: (version) => { delete versions[version] },
empty: () => { versions = {} }
set: (version, store) => { versions[version] = store }
}

@@ -499,3 +495,3 @@ },

To include a display of the `store` data passed to individual routes, the
To include a display of the `store` data passed to individual routes, the
option `includeMeta` may be passed. If set to `true` all items will be

@@ -502,0 +498,0 @@ displayed, this can also be set to an array specifying which keys (if

@@ -28,27 +28,1 @@ const acceptHostStrategy = require('../lib/strategies/accept-host')

})
t.test('exact host matches can be removed', async (t) => {
const storage = acceptHostStrategy.storage()
storage.set('fastify.io', true)
t.equal(storage.get('fastify.io'), true)
storage.del('fastify.io')
t.equal(storage.get('fastify.io'), undefined)
})
t.test('regexp host matches can be removed', async (t) => {
const storage = acceptHostStrategy.storage()
t.equal(storage.get('fastify.io'), undefined)
storage.set(/.+fastify\.io/, true)
t.equal(storage.get('foo.fastify.io'), true)
storage.del(/.+fastify\.io/)
t.equal(storage.get('foo.fastify.io'), undefined)
})
t.test('storage can be emptied', async (t) => {
const storage = acceptHostStrategy.storage()
storage.set(/.+fastify\.io/, 'wildcard')
storage.set('auth.fastify.io', 'exact')
storage.empty()
t.equal(storage.get('fastify.io'), undefined)
t.equal(storage.get('foo.fastify.io'), undefined)
})

@@ -37,2 +37,19 @@ 'use strict'

test('route with an extension regex 2', t => {
t.plan(2)
const findMyWay = FindMyWay({
defaultRoute: (req) => {
t.fail(`route not matched: ${req.url}`)
}
})
findMyWay.on('GET', '/test/S/:file(^\\S+).png', () => {
t.ok('regex match')
})
findMyWay.on('GET', '/test/D/:file(^\\D+).png', () => {
t.ok('regex match')
})
findMyWay.lookup({ method: 'GET', url: '/test/S/foo.png', headers: {} }, null)
findMyWay.lookup({ method: 'GET', url: '/test/D/foo.png', headers: {} }, null)
})
test('nested route with matching regex', t => {

@@ -39,0 +56,0 @@ t.plan(1)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc