Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WIP: Optimized matcher #3707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(optimized matcher): Test sensitive flag for static routes.
  • Loading branch information
iurisilvio committed Jan 30, 2022
commit 44f4bf59a119e3c829c0999a6b3a3a976a817658
13 changes: 12 additions & 1 deletion 13 src/create-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,24 @@ function optimizedMatcher (
const route = pathMap[path]
if (isStaticPath(path)) {
staticMap[path] = { index, route }
if (route.regex.ignoreCase) {
staticMap[path.toLowerCase()] = { index, route }
}
} else {
dynamics.push({ index, route })
}
})

function match (location) {
const staticRecord = staticMap[location.path.replace(/\/$/, '')]
const cleanPath = location.path.replace(/\/$/, '')
let staticRecord = staticMap[cleanPath]

if (!staticRecord) {
const staticRecordInsensitive = staticMap[cleanPath.toLowerCase()]
if (staticRecordInsensitive && staticRecordInsensitive.route.regex.ignoreCase) {
staticRecord = staticRecordInsensitive
}
}

for (var i = 0; i < dynamics.length; i++) {
const { index, route } = dynamics[i]
Expand Down
24 changes: 24 additions & 0 deletions 24 test/unit/specs/create-matcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,28 @@ describe('Creating Matcher', function () {
expect(matcher.match('/p/staticbefore').name).toBe('staticbefore')
expect(matcher.match('/p/staticafter').name).toBe('dynamic')
})

it('static can be sensitive', function () {
const matcher = createMatcher([
{
path: '/p/sensitive',
name: 'sensitive',
pathToRegexpOptions: {
sensitive: true
},
component: { name: 'sensitive' }
},
{
path: '/p/insensitive',
name: 'insensitive',
component: { name: 'insensitive' }
},
{
path: '*', name: 'not-found', component: { name: 'not-found ' }
}
])

expect(matcher.match('/p/SENSITIVE').name).toBe('not-found')
expect(matcher.match('/p/INSENSITIVE').name).toBe('insensitive')
})
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.