Skip to content

Commit

Permalink
fix(stega): update default filter to skip paths that contain "type" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Apr 5, 2024
1 parent 560d091 commit 1c6e4ea
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/stega/filterDefault.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {FilterDefault} from './types'
import type {ContentSourceMapParsedPath, FilterDefault} from './types'

export const filterDefault: FilterDefault = ({sourcePath, value}) => {
export const filterDefault: FilterDefault = ({sourcePath, resultPath, value}) => {
// Skips encoding on URL or Date strings, similar to the `skip: 'auto'` parameter in vercelStegaCombine()
if (isValidDate(value) || isValidURL(value)) {
return false
Expand Down Expand Up @@ -50,6 +50,12 @@ export const filterDefault: FilterDefault = ({sourcePath, value}) => {
return false
}

// If the sourcePath or resultPath contains something that sounds like a type, like iconType, we skip encoding, as it's most
// of the time used for logic that breaks if it contains stega characters
if (hasTypeLike(sourcePath) || hasTypeLike(resultPath)) {
return false
}

// Finally, we ignore a bunch of paths that are typically used for page building
if (typeof endPath === 'string' && denylist.has(endPath)) {
return false
Expand Down Expand Up @@ -111,3 +117,7 @@ function isValidURL(url: string) {
}
return true
}

function hasTypeLike(path: ContentSourceMapParsedPath): boolean {
return path.some((segment) => typeof segment === 'string' && segment.match(/type/i) !== null)
}

0 comments on commit 1c6e4ea

Please sign in to comment.