-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Core: Improve addon sanitization #33554
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,12 +44,56 @@ export const metaFrameworks = { | |||||
| } as Record<string, string>; | ||||||
|
|
||||||
| export const sanitizeAddonName = (name: string) => { | ||||||
| return cleanPaths(name) | ||||||
| const normalized = name.replace(/\\/g, '/'); | ||||||
|
|
||||||
| let candidate: string = normalized; | ||||||
|
|
||||||
| if (normalized.includes('/node_modules/')) { | ||||||
| // common case for package manager cache/pnp mode so we take the segment after node_modules | ||||||
| candidate = normalized.split('/node_modules/').pop() ?? normalized; | ||||||
| } | ||||||
|
|
||||||
| const cleaned = cleanPaths(candidate) | ||||||
| .replace(/^file:\/\//i, '') | ||||||
| .replace(/\/+$/, '') | ||||||
| .replace(/\/dist\/.*/, '') | ||||||
| .replace(/\.[mc]?[tj]?s[x]?$/, '') | ||||||
| .replace(/\/register$/, '') | ||||||
| .replace(/\/manager$/, '') | ||||||
| .replace(/\/preset$/, ''); | ||||||
| .replace(/\/(register|manager|preset|index)$/, '') | ||||||
| .replace(/\$SNIP?/g, ''); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regex likely matches unintended pattern. The regex Proposed fix- .replace(/\$SNIP?/g, '');
+ .replace(/\$SNIP/g, '');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| let prefix = ''; | ||||||
| if ( | ||||||
| cleaned.startsWith('file') || | ||||||
| cleaned.startsWith('.') || | ||||||
| cleaned.startsWith('/') || | ||||||
| cleaned.includes(':') | ||||||
| ) { | ||||||
| prefix = 'CUSTOM:'; | ||||||
| } | ||||||
|
|
||||||
| const scopedMatches = cleaned.match(/@[^/]+\/[^/]+/g); | ||||||
| if (scopedMatches?.length) { | ||||||
| return scopedMatches.at(-1) as string; | ||||||
| } | ||||||
|
|
||||||
| const parts = cleaned.split('/').filter(Boolean); | ||||||
| const addonLike = [...parts] | ||||||
| .reverse() | ||||||
| .find((part) => part.includes('addon-') || part.includes('-addon')); | ||||||
|
|
||||||
| if (addonLike) { | ||||||
| return `${prefix}${addonLike}`; | ||||||
| } | ||||||
|
|
||||||
| if (parts.length >= 2 && parts[parts.length - 2].startsWith('@')) { | ||||||
| return `${prefix}${parts[parts.length - 2]}/${parts[parts.length - 1]}`; | ||||||
| } | ||||||
|
|
||||||
| if (parts.length) { | ||||||
| return `${prefix}${parts[parts.length - 1]}`; | ||||||
| } | ||||||
|
|
||||||
| return `${prefix}${candidate}`; | ||||||
| }; | ||||||
|
|
||||||
| // Analyze a combination of information from main.js and package.json | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.