Skip to content

Commit 426f3b5

Browse files
committed
linting
1 parent 4aa2e15 commit 426f3b5

File tree

6 files changed

+56
-55
lines changed

6 files changed

+56
-55
lines changed

lib/router/sequential.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ module.exports = (config = {}) => {
5858
*/
5959
let cache = null
6060
if (cacheSize > 0) {
61-
cache = new Cache({
61+
cache = new Cache({
6262
max: cacheSize,
6363
updateAgeOnGet: false, // Disable age updates for better performance
6464
updateAgeOnHas: false
6565
})
6666
} else if (cacheSize < 0) {
6767
// Reduced from 100k to 50k for better memory efficiency while maintaining performance
68-
cache = new Cache({
68+
cache = new Cache({
6969
max: 50000,
7070
updateAgeOnGet: false,
7171
updateAgeOnHas: false

lib/utils/queryparams.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const EMPTY_QUERY = Object.freeze(Object.create(null))
77
module.exports = (req, url) => {
88
// Single indexOf call - more efficient than multiple operations
99
const questionMarkIndex = url.indexOf('?')
10-
10+
1111
if (questionMarkIndex === -1) {
1212
// Fast path: no query string
1313
req.path = url
@@ -17,7 +17,7 @@ module.exports = (req, url) => {
1717

1818
// Use Object.create(null) for prototype pollution protection
1919
const query = Object.create(null)
20-
20+
2121
// Extract path and search in one operation each
2222
req.path = url.slice(0, questionMarkIndex)
2323
const search = url.slice(questionMarkIndex + 1)
@@ -30,13 +30,13 @@ module.exports = (req, url) => {
3030

3131
// Process query parameters with optimized URLSearchParams handling
3232
const searchParams = new URLSearchParams(search.replace(/\[\]=/g, '='))
33-
33+
3434
for (const [name, value] of searchParams.entries()) {
3535
// Use Set for O(1) dangerous property lookup instead of multiple string comparisons
3636
if (DANGEROUS_PROPERTIES.has(name)) {
3737
continue // Skip dangerous property names
3838
}
39-
39+
4040
const existing = query[name]
4141
if (existing !== undefined) {
4242
// Optimized array handling - check type once, then branch

tooling/advanced-pollution-test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ console.log('Advanced prototype pollution protection test...\n')
1212
const testCases = [
1313
// Standard URLSearchParams parsing might decode these differently
1414
'/test?__proto__=polluted',
15-
'/test?constructor=polluted',
15+
'/test?constructor=polluted',
1616
'/test?prototype=polluted',
17-
17+
1818
// URL encoded versions
19-
'/test?%5F%5Fproto%5F%5F=polluted', // __proto__
20-
'/test?constructor%2Eprototype=polluted', // constructor.prototype
21-
19+
'/test?%5F%5Fproto%5F%5F=polluted', // __proto__
20+
'/test?constructor%2Eprototype=polluted', // constructor.prototype
21+
2222
// Multiple same-name parameters (should create arrays)
2323
'/test?__proto__=value1&__proto__=value2',
2424
'/test?constructor=value1&constructor=value2',
25-
25+
2626
// Mixed dangerous and safe parameters
27-
'/test?safe=value&__proto__=polluted&another=safe',
27+
'/test?safe=value&__proto__=polluted&another=safe'
2828
]
2929

3030
console.log('Before tests:')
3131
console.log('- Object.prototype.polluted:', Object.prototype.polluted)
3232
console.log('- Object.prototype.testProp:', Object.prototype.testProp)
3333

3434
// Mock request/response objects
35-
function createMockReq(url) {
35+
function createMockReq (url) {
3636
return {
3737
method: 'GET',
38-
url: url,
38+
url,
3939
headers: {}
4040
}
4141
}
4242

43-
function createMockRes() {
43+
function createMockRes () {
4444
return {
4545
statusCode: 200,
4646
writeHead: () => {},
@@ -54,18 +54,18 @@ const router = sequential()
5454
// Test each case
5555
testCases.forEach((testUrl, index) => {
5656
console.log(`\n--- Test ${index + 1}: ${testUrl} ---`)
57-
57+
5858
const req = createMockReq(testUrl)
5959
const res = createMockRes()
60-
60+
6161
// Mock a simple route handler
6262
router.get('/test', (req, res) => {
6363
console.log('Query keys:', Object.keys(req.query))
6464
console.log('Query values:', req.query)
6565
console.log('Prototype:', Object.getPrototypeOf(req.query))
6666
res.end()
6767
})
68-
68+
6969
try {
7070
router.lookup(req, res)
7171
} catch (error) {
@@ -80,6 +80,7 @@ console.log('- Object.prototype.testProp:', Object.prototype.testProp)
8080
// Test if we can access dangerous properties through any means
8181
try {
8282
const testObj = {}
83+
/* eslint-disable no-proto */
8384
console.log('- testObj.__proto__:', testObj.__proto__)
8485
console.log('- testObj.constructor:', testObj.constructor)
8586
} catch (e) {

tooling/performance-test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ const scenarios = [
4242
]
4343

4444
// Mock request/response objects
45-
function createMockReq(url) {
45+
function createMockReq (url) {
4646
return {
4747
method: 'GET',
48-
url: url,
48+
url,
4949
headers: {}
5050
}
5151
}
5252

53-
function createMockRes() {
53+
function createMockRes () {
5454
return {
5555
statusCode: 200,
5656
writeHead: () => {},
@@ -63,35 +63,35 @@ function createMockRes() {
6363
for (const config of testConfigs) {
6464
console.log(`📊 Testing: ${config.name}`)
6565
console.log('─'.repeat(50))
66-
66+
6767
for (const scenario of scenarios) {
6868
const router = sequential({ cacheSize: config.cacheSize })
6969
scenario.setup(router)
70-
70+
7171
// Warm up
7272
for (let i = 0; i < 1000; i++) {
7373
const req = createMockReq(scenario.url)
7474
const res = createMockRes()
7575
router.lookup(req, res)
7676
}
77-
77+
7878
// Benchmark
7979
const iterations = 50000
8080
const start = process.hrtime.bigint()
81-
81+
8282
for (let i = 0; i < iterations; i++) {
8383
const req = createMockReq(scenario.url)
8484
const res = createMockRes()
8585
router.lookup(req, res)
8686
}
87-
87+
8888
const end = process.hrtime.bigint()
8989
const totalTime = Number(end - start)
9090
const avgTime = totalTime / iterations
91-
91+
9292
console.log(` ${scenario.name.padEnd(25)} ${(avgTime / 1000).toFixed(2).padStart(8)} µs/op`)
9393
}
94-
94+
9595
console.log()
9696
}
9797

@@ -105,22 +105,22 @@ const queryTests = [
105105
'/path?simple=value',
106106
'/path?a=1&b=2&c=3&d=4&e=5',
107107
'/path?arr=1&arr=2&arr=3&arr=4',
108-
'/path?complex=val&simple=test&arr=1&arr=2&encoded=%20%21',
108+
'/path?complex=val&simple=test&arr=1&arr=2&encoded=%20%21'
109109
]
110110

111111
for (const url of queryTests) {
112112
const iterations = 100000
113113
const start = process.hrtime.bigint()
114-
114+
115115
for (let i = 0; i < iterations; i++) {
116116
const req = {}
117117
queryparams(req, url)
118118
}
119-
119+
120120
const end = process.hrtime.bigint()
121121
const totalTime = Number(end - start)
122122
const avgTime = totalTime / iterations
123-
123+
124124
const queryDesc = url.includes('?') ? `${url.split('?')[1].split('&').length} params` : 'no query'
125125
console.log(` ${queryDesc.padEnd(15)} ${(avgTime / 1000).toFixed(2).padStart(8)} µs/op`)
126126
}
@@ -143,7 +143,7 @@ for (let i = 0; i < 10000; i++) {
143143
`/users/${i}?query=test`,
144144
`/nonexistent/${i}`
145145
]
146-
146+
147147
for (const url of urls) {
148148
const req = createMockReq(url)
149149
const res = createMockRes()

tooling/prototype-pollution-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ router.get('/test', (req, res) => {
1818
console.log('Has __proto__ property:', '__proto__' in req.query)
1919
console.log('Has constructor property:', 'constructor' in req.query)
2020
console.log('Query object prototype:', Object.getPrototypeOf(req.query))
21-
21+
2222
res.writeHead(200, { 'Content-Type': 'application/json' })
2323
res.end(JSON.stringify({
2424
query: req.query,
@@ -41,15 +41,15 @@ const testCases = [
4141
console.log('Before tests - Object.prototype.polluted:', Object.prototype.polluted)
4242

4343
// Mock request/response objects for testing
44-
function createMockReq(url) {
44+
function createMockReq (url) {
4545
return {
4646
method: 'GET',
47-
url: url,
47+
url,
4848
headers: {}
4949
}
5050
}
5151

52-
function createMockRes() {
52+
function createMockRes () {
5353
let data = ''
5454
return {
5555
statusCode: 200,
@@ -63,10 +63,10 @@ function createMockRes() {
6363
// Test each case
6464
testCases.forEach((testUrl, index) => {
6565
console.log(`\n--- Test ${index + 1}: ${testUrl} ---`)
66-
66+
6767
const req = createMockReq(testUrl)
6868
const res = createMockRes()
69-
69+
7070
try {
7171
router.lookup(req, res)
7272
const responseData = JSON.parse(res._getData())

tooling/queryparams-benchmark.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const queryparams = require('../lib/utils/queryparams')
88

99
// Test cases that cover different scenarios
1010
const testCases = [
11-
'/path', // No query string
12-
'/path?', // Empty query string
13-
'/path?simple=value', // Single parameter
14-
'/path?a=1&b=2&c=3', // Multiple parameters
15-
'/path?arr=1&arr=2&arr=3', // Array parameters
11+
'/path', // No query string
12+
'/path?', // Empty query string
13+
'/path?simple=value', // Single parameter
14+
'/path?a=1&b=2&c=3', // Multiple parameters
15+
'/path?arr=1&arr=2&arr=3', // Array parameters
1616
'/path?complex=val1&simple=val2&arr=1&arr=2', // Mixed parameters
17-
'/path?encoded=%20%21%40%23', // URL encoded values
18-
'/path?empty=&another=value', // Empty values
19-
'/path?dangerous=safe&normal=value', // Safe parameters with dangerous-sounding names
17+
'/path?encoded=%20%21%40%23', // URL encoded values
18+
'/path?empty=&another=value', // Empty values
19+
'/path?dangerous=safe&normal=value' // Safe parameters with dangerous-sounding names
2020
]
2121

2222
console.log('Micro-benchmarking queryparams performance...\n')
@@ -33,25 +33,25 @@ for (let i = 0; i < 1000; i++) {
3333
testCases.forEach((url, index) => {
3434
const iterations = 100000
3535
const req = {}
36-
36+
3737
console.log(`Test ${index + 1}: ${url}`)
38-
38+
3939
const start = process.hrtime.bigint()
40-
40+
4141
for (let i = 0; i < iterations; i++) {
4242
// Create a fresh req object each time to avoid caching effects
4343
const testReq = {}
4444
queryparams(testReq, url)
4545
}
46-
46+
4747
const end = process.hrtime.bigint()
4848
const totalTime = Number(end - start)
4949
const avgTime = totalTime / iterations
50-
50+
5151
console.log(` ${iterations.toLocaleString()} iterations`)
5252
console.log(` Average: ${(avgTime / 1000).toFixed(2)} µs per operation`)
5353
console.log(` Total: ${(totalTime / 1000000).toFixed(2)} ms`)
54-
54+
5555
// Verify the result is correct
5656
queryparams(req, url)
5757
console.log(` Result: path="${req.path}", query keys=[${Object.keys(req.query).join(', ')}]`)
@@ -62,7 +62,7 @@ testCases.forEach((url, index) => {
6262
console.log('Security verification:')
6363
const securityTests = [
6464
'/test?__proto__=polluted',
65-
'/test?constructor=dangerous',
65+
'/test?constructor=dangerous',
6666
'/test?prototype=unsafe',
6767
'/test?safe=value&__proto__=attack&normal=ok'
6868
]

0 commit comments

Comments
 (0)