Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: honojs/hono
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.11.6
Choose a base ref
...
head repository: honojs/hono
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.11.7
Choose a head ref
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 13, 2023

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    hi-ogawa Hiroshi Ogawa
    Copy the full SHA
    18b6282 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    hi-ogawa Hiroshi Ogawa
    Copy the full SHA
    af9e485 View commit details

Commits on Dec 14, 2023

  1. Merge pull request from GHSA-f6gv-hh8j-q8vq

    * fix(trie-router): don't remain with the values of named param
    
    * denoify
    
    * fix: don't share `params`
    
    * denoify
    yusukebe authored Dec 14, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    hi-ogawa Hiroshi Ogawa
    Copy the full SHA
    8e2b6b0 View commit details
  2. v3.11.7

    yusukebe committed Dec 14, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    hi-ogawa Hiroshi Ogawa
    Copy the full SHA
    8edb160 View commit details
Showing with 612 additions and 691 deletions.
  1. +3 −62 .eslintrc.cjs
  2. +8 −3 .vscode/settings.json
  3. +17 −12 deno_dist/router/trie-router/node.ts
  4. +7 −16 package.json
  5. +15 −0 src/router/trie-router/node.test.ts
  6. +17 −12 src/router/trie-router/node.ts
  7. +545 −586 yarn.lock
65 changes: 3 additions & 62 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
const { defineConfig } = require('eslint-define-config')

module.exports = defineConfig({
root: true,
extends: [
'eslint:recommended',
'plugin:node/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021,
},
plugins: ['@typescript-eslint', 'import'],
globals: {
fetch: false,
Response: false,
Request: false,
addEventListener: false,
},
rules: {
quotes: ['error', 'single'],
semi: ['error', 'never'],
'no-debugger': ['error'],
'no-empty': ['warn', { allowEmptyCatch: true }],
'no-process-exit': 'off',
'no-useless-escape': 'off',
'prefer-const': [
'warn',
{
destructuring: 'all',
},
],
'@typescript-eslint/ban-types': [
'error',
{
types: {
Function: false,
'{}': false,
},
},
],
'sort-imports': 0,
'import/order': [2, { alphabetize: { order: 'asc' } }],

'node/no-missing-import': 'off',
'node/no-missing-require': 'off',
'node/no-deprecated-api': 'off',
'node/no-unpublished-import': 'off',
'node/no-unpublished-require': 'off',
'node/no-unsupported-features/es-syntax': 'off',

'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
},
ignorePatterns: ['dist'],
})
module.exports = {
extends: ['@hono/eslint-config'],
}
11 changes: 8 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"deno.enable": false,
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
}
29 changes: 17 additions & 12 deletions deno_dist/router/trie-router/node.ts
Original file line number Diff line number Diff line change
@@ -5,12 +5,15 @@ import { splitPath, splitRoutingPath, getPattern } from '../../utils/url.ts'

type HandlerSet<T> = {
handler: T
params: Record<string, string>
possibleKeys: string[]
score: number
name: string // For debug
}

type HandlerParamsSet<T> = HandlerSet<T> & {
params: Record<string, string>
}

export class Node<T> {
methods: Record<string, HandlerSet<T>>[]

@@ -26,7 +29,7 @@ export class Node<T> {
this.name = ''
if (method && handler) {
const m: Record<string, HandlerSet<T>> = {}
m[method] = { handler, params: {}, possibleKeys: [], score: 0, name: this.name }
m[method] = { handler, possibleKeys: [], score: 0, name: this.name }
this.methods = [m]
}
this.patterns = []
@@ -74,7 +77,6 @@ export class Node<T> {

const handlerSet: HandlerSet<T> = {
handler,
params: {},
possibleKeys,
name: this.name,
score: this.order,
@@ -87,12 +89,17 @@ export class Node<T> {
}

// getHandlerSets
private gHSets(node: Node<T>, method: string, params: Record<string, string>): HandlerSet<T>[] {
const handlerSets: HandlerSet<T>[] = []
private gHSets(
node: Node<T>,
method: string,
params: Record<string, string>
): HandlerParamsSet<T>[] {
const handlerSets: HandlerParamsSet<T>[] = []
for (let i = 0, len = node.methods.length; i < len; i++) {
const m = node.methods[i]
const handlerSet = m[method] || m[METHOD_NAME_ALL]
const handlerSet = (m[method] || m[METHOD_NAME_ALL]) as HandlerParamsSet<T>
if (handlerSet !== undefined) {
handlerSet.params = {}
handlerSet.possibleKeys.map((key) => {
handlerSet.params[key] = params[key]
})
@@ -103,7 +110,7 @@ export class Node<T> {
}

search(method: string, path: string): [[T, Params][]] {
const handlerSets: HandlerSet<T>[] = []
const handlerSets: HandlerParamsSet<T>[] = []

const params: Record<string, string> = {}
this.params = {}
@@ -126,11 +133,9 @@ export class Node<T> {
if (isLast === true) {
// '/hello/*' => match '/hello'
if (nextNode.children['*']) {
handlerSets.push(
...this.gHSets(nextNode.children['*'], method, { ...params, ...node.params })
)
handlerSets.push(...this.gHSets(nextNode.children['*'], method, node.params))
}
handlerSets.push(...this.gHSets(nextNode, method, { ...params, ...node.params }))
handlerSets.push(...this.gHSets(nextNode, method, node.params))
} else {
tempNodes.push(nextNode)
}
@@ -144,7 +149,7 @@ export class Node<T> {
if (pattern === '*') {
const astNode = node.children['*']
if (astNode) {
handlerSets.push(...this.gHSets(astNode, method, { ...params, ...node.params }))
handlerSets.push(...this.gHSets(astNode, method, node.params))
tempNodes.push(astNode)
}
continue
23 changes: 7 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hono",
"version": "3.11.6",
"version": "3.11.7",
"description": "Ultrafast web framework for the Edges",
"main": "dist/cjs/index.js",
"type": "module",
@@ -20,8 +20,8 @@
"test:lambda": "env NAME=Node vitest --run --config ./runtime_tests/lambda/vitest.config.ts",
"test:lambda-edge": "env NAME=Node vitest --run --config ./runtime_tests/lambda-edge/vitest.config.ts",
"test:all": "yarn test && yarn test:deno && yarn test:bun && yarn test:fastly && yarn test:lagon && yarn test:node && yarn test:wrangler && yarn test:lambda && yarn test:lambda-edge",
"lint": "eslint --ext js,ts src runtime_tests .eslintrc.cjs",
"lint:fix": "eslint --ext js,ts src runtime_tests .eslintrc.cjs --fix",
"lint": "eslint --ext js,ts src runtime_tests",
"lint:fix": "eslint --ext js,ts src runtime_tests --fix",
"format": "prettier --check 'src/**/*.{js,ts}' 'runtime_tests/**/*.{js,ts}'",
"format:fix": "prettier --write 'src/**/*.{js,ts}' 'runtime_tests/**/*.{js,ts}'",
"denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.{ts,tsx}'",
@@ -442,6 +442,7 @@
],
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@hono/eslint-config": "^0.0.2",
"@hono/node-server": "^1.0.2",
"@types/crypto-js": "^4.1.1",
"@types/glob": "^8.0.0",
@@ -450,21 +451,12 @@
"@types/node": "^20.8.2",
"@types/node-fetch": "^2.6.2",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"@vitest/coverage-v8": "^0.34.3",
"arg": "^5.0.2",
"crypto-js": "^4.1.1",
"denoify": "^1.6.6",
"esbuild": "^0.15.12",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"eslint-define-config": "^1.20.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint": "^8.55.0",
"form-data": "^4.0.0",
"jest": "^29.6.4",
"jest-preset-fastly-js-compute": "^1.3.0",
@@ -479,13 +471,12 @@
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"tsx": "^3.11.0",
"typescript": "^4.8.3",
"typescript": "^5.3.3",
"vitest": "^0.34.3",
"wrangler": "^2.12.0",
"zod": "^3.20.2"
},
"engines": {
"node": ">=16.0.0"
},
"dependencies": {}
}
}
15 changes: 15 additions & 0 deletions src/router/trie-router/node.test.ts
Original file line number Diff line number Diff line change
@@ -89,6 +89,21 @@ describe('Name path', () => {
expect(res[0][0]).toEqual('get events')
expect(res[0][1]['location']).toBe('yokohama')
})

it('Should not return a previous param value', () => {
const node = new Node()
node.insert('delete', '/resource/:id', 'resource')
const [resA] = node.search('delete', '/resource/a')
const [resB] = node.search('delete', '/resource/b')
expect(resA).not.toBeNull()
expect(resA.length).toBe(1)
expect(resA[0][0]).toEqual('resource')
expect(resA[0][1]).toEqual({ id: 'a' })
expect(resB).not.toBeNull()
expect(resB.length).toBe(1)
expect(resB[0][0]).toEqual('resource')
expect(resB[0][1]).toEqual({ id: 'b' })
})
})

describe('Name path - Multiple route', () => {
29 changes: 17 additions & 12 deletions src/router/trie-router/node.ts
Original file line number Diff line number Diff line change
@@ -5,12 +5,15 @@ import { splitPath, splitRoutingPath, getPattern } from '../../utils/url'

type HandlerSet<T> = {
handler: T
params: Record<string, string>
possibleKeys: string[]
score: number
name: string // For debug
}

type HandlerParamsSet<T> = HandlerSet<T> & {
params: Record<string, string>
}

export class Node<T> {
methods: Record<string, HandlerSet<T>>[]

@@ -26,7 +29,7 @@ export class Node<T> {
this.name = ''
if (method && handler) {
const m: Record<string, HandlerSet<T>> = {}
m[method] = { handler, params: {}, possibleKeys: [], score: 0, name: this.name }
m[method] = { handler, possibleKeys: [], score: 0, name: this.name }
this.methods = [m]
}
this.patterns = []
@@ -74,7 +77,6 @@ export class Node<T> {

const handlerSet: HandlerSet<T> = {
handler,
params: {},
possibleKeys,
name: this.name,
score: this.order,
@@ -87,12 +89,17 @@ export class Node<T> {
}

// getHandlerSets
private gHSets(node: Node<T>, method: string, params: Record<string, string>): HandlerSet<T>[] {
const handlerSets: HandlerSet<T>[] = []
private gHSets(
node: Node<T>,
method: string,
params: Record<string, string>
): HandlerParamsSet<T>[] {
const handlerSets: HandlerParamsSet<T>[] = []
for (let i = 0, len = node.methods.length; i < len; i++) {
const m = node.methods[i]
const handlerSet = m[method] || m[METHOD_NAME_ALL]
const handlerSet = (m[method] || m[METHOD_NAME_ALL]) as HandlerParamsSet<T>
if (handlerSet !== undefined) {
handlerSet.params = {}
handlerSet.possibleKeys.map((key) => {
handlerSet.params[key] = params[key]
})
@@ -103,7 +110,7 @@ export class Node<T> {
}

search(method: string, path: string): [[T, Params][]] {
const handlerSets: HandlerSet<T>[] = []
const handlerSets: HandlerParamsSet<T>[] = []

const params: Record<string, string> = {}
this.params = {}
@@ -126,11 +133,9 @@ export class Node<T> {
if (isLast === true) {
// '/hello/*' => match '/hello'
if (nextNode.children['*']) {
handlerSets.push(
...this.gHSets(nextNode.children['*'], method, { ...params, ...node.params })
)
handlerSets.push(...this.gHSets(nextNode.children['*'], method, node.params))
}
handlerSets.push(...this.gHSets(nextNode, method, { ...params, ...node.params }))
handlerSets.push(...this.gHSets(nextNode, method, node.params))
} else {
tempNodes.push(nextNode)
}
@@ -144,7 +149,7 @@ export class Node<T> {
if (pattern === '*') {
const astNode = node.children['*']
if (astNode) {
handlerSets.push(...this.gHSets(astNode, method, { ...params, ...node.params }))
handlerSets.push(...this.gHSets(astNode, method, node.params))
tempNodes.push(astNode)
}
continue
Loading