Socket
Socket
Sign inDemoInstall

find-my-way

Package Overview
Dependencies
Maintainers
2
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-my-way - npm Package Compare versions

Comparing version 4.5.0 to 4.5.1

44

node.js

@@ -66,9 +66,15 @@ 'use strict'

this.children[label] = node
this.numberOfChildren = Object.keys(this.children).length
const labels = Object.keys(this.children)
var parametricBrother = this.parametricBrother
for (var i = 0; i < labels.length; i++) {
const child = this.children[labels[i]]
if (child.label === ':') {
const nodeChildren = Object.values(this.children)
this.numberOfChildren = nodeChildren.length
this._saveParametricBrother()
return this
}
Node.prototype._saveParametricBrother = function () {
let parametricBrother = this.parametricBrother
for (const child of Object.values(this.children)) {
if (child.prefix === ':') {
parametricBrother = child

@@ -80,24 +86,10 @@ break

// Save the parametric brother inside static children
const iterate = (node) => {
if (!node) {
return
if (parametricBrother) {
for (const child of Object.values(this.children)) {
if (child && child.kind === this.types.STATIC) {
child.parametricBrother = parametricBrother
child._saveParametricBrother(parametricBrother)
}
}
if (node.kind !== this.types.STATIC) {
return
}
if (node !== this) {
node.parametricBrother = parametricBrother || node.parametricBrother
}
const labels = Object.keys(node.children)
for (var i = 0; i < labels.length; i++) {
iterate(node.children[labels[i]])
}
}
iterate(this)
return this
}

@@ -104,0 +96,0 @@

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -150,2 +150,25 @@ 'use strict'

test('Parent parametric brother should not rewrite child node parametric brother', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.fail('Should not be defaultRoute')
}
})
findMyWay.on('GET', '/text/hello', (req, res, params) => {
res.end('{"hello":"world"}')
})
findMyWay.on('GET', '/text/:e/test', (req, res, params) => {
res.end('{"winter":"is here"}')
})
findMyWay.on('GET', '/:c', (req, res, params) => {
res.end('{"hello":"world"}')
})
t.same(findMyWay.find('GET', '/text/hellos/test').params, { e: 'hellos' })
})
test('Mixed parametric routes, with last defined route being static', t => {

@@ -152,0 +175,0 @@ t.plan(4)

@@ -32,1 +32,51 @@ 'use strict'

})
test('double colon is replaced with single colon, no parameters, same parent node name', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: () => t.fail('should not be default route')
})
findMyWay.on('GET', '/name', () => {
t.fail('should not be parent route')
})
findMyWay.on('GET', '/name::customVerb', (req, res, params) => {
t.same(params, {})
})
findMyWay.lookup({ method: 'GET', url: '/name:customVerb', headers: {} }, null)
})
test('double colon is replaced with single colon, default route, same parent node name', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: () => t.ok('should be default route')
})
findMyWay.on('GET', '/name', () => {
t.fail('should not be parent route')
})
findMyWay.on('GET', '/name::customVerb', () => {
t.fail('should not be child route')
})
findMyWay.lookup({ method: 'GET', url: '/name:wrongCustomVerb', headers: {} }, null)
})
test('double colon is replaced with single colon, with parameters', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: () => t.fail('should not be default route')
})
findMyWay.on('GET', '/name1::customVerb1/:param1/name2::customVerb2:param2', (req, res, params) => {
t.same(params, {
param1: 'value1',
param2: 'value2'
})
})
findMyWay.lookup({ method: 'GET', url: '/name1:customVerb1/value1/name2:customVerb2value2', headers: {} }, null)
})
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