Skip to content
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

fix(waku/router): regex in file replacement to correctly handle all matches (fs-router) #678

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/waku/src/router/fs-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function fsRouter(
return [];
}
// HACK: replace "_slug_" to "[slug]" for build
file = file.replace(/(^|\/|\\)_([^/]+)_(\/|\\|\.)/g, '$1[$2]$3');
file = file.replace(/(?<=^|\/|\\)_([^/]+)_(?=\/|\\|\.)/g, '[$1]');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, nice. I should improve my regex skill.

(We need to avoid this HACK, but if it's not soon, we should probably extract the logic into a function and add a test for it.)

// For Windows
file = sep === '/' ? file : file.replace(/\\/g, '/');
// HACK: resolve different extensions for build
Expand Down
Loading