Skip to content

Commit 1c6e4ea

Browse files
authored
fix(stega): update default filter to skip paths that contain "type" (#689)
1 parent 560d091 commit 1c6e4ea

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/stega/filterDefault.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type {FilterDefault} from './types'
1+
import type {ContentSourceMapParsedPath, FilterDefault} from './types'
22

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

53+
// If the sourcePath or resultPath contains something that sounds like a type, like iconType, we skip encoding, as it's most
54+
// of the time used for logic that breaks if it contains stega characters
55+
if (hasTypeLike(sourcePath) || hasTypeLike(resultPath)) {
56+
return false
57+
}
58+
5359
// Finally, we ignore a bunch of paths that are typically used for page building
5460
if (typeof endPath === 'string' && denylist.has(endPath)) {
5561
return false
@@ -111,3 +117,7 @@ function isValidURL(url: string) {
111117
}
112118
return true
113119
}
120+
121+
function hasTypeLike(path: ContentSourceMapParsedPath): boolean {
122+
return path.some((segment) => typeof segment === 'string' && segment.match(/type/i) !== null)
123+
}

0 commit comments

Comments
 (0)