Skip to content

Commit

Permalink
fix(module): only safelist known colors
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Jun 13, 2023
1 parent ccd9ca5 commit cdce519
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ export const excludeColors = (colors: object) => Object.keys(omit(colors, colors

export const generateSafelist = (colors: string[]) => ['avatar', 'badge', 'button', 'input', 'notification'].flatMap(component => safelistByComponent[component](colorsAsRegex(colors)))

export const customSafelistExtractor = (prefix, content: string) => {
export const customSafelistExtractor = (prefix, content: string, colors: string[]) => {
const classes = []
const regex = /<(\w+)\s+[^>:]*color=["']([^"']+)["'][^>]*>/gs
const matches = [...content.matchAll(regex)]

for (const match of matches) {
const [, component, color] = match

if (colorsToExclude.includes(color)) {
if (!colors.includes(color)) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default defineNuxtModule<ModuleOptions>({
vue: (content) => {
return [
...defaultExtractor(content),
...customSafelistExtractor(options.prefix, content)
...customSafelistExtractor(options.prefix, content, nuxt.options.appConfig.ui.colors)
]
}
}
Expand Down

1 comment on commit cdce519

@vercel
Copy link

@vercel vercel bot commented on cdce519 Jun 13, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

ui – ./

ui.nuxtlabs.com
ui-git-dev-nuxtlabs.vercel.app
ui-nuxtlabs.vercel.app

Please sign in to comment.