chore: more strict mem limit for string filters

This commit is contained in:
Harttle
2026-03-22 22:10:39 +08:00
parent 95ddefc056
commit 94440a0653
3 changed files with 47 additions and 30 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
import { FS } from './fs'
import { assert, escapeRegex } from '../util'
import { assert } from '../util'
export interface LoaderOptions {
fs: FS;
@@ -24,8 +24,8 @@ export class Loader {
if (options.relativeReference) {
const sep = options.fs.sep
assert(sep, '`fs.sep` is required for relative reference')
const rRelativePath = new RegExp(['.' + sep, '..' + sep, './', '../'].map(prefix => escapeRegex(prefix)).join('|'))
this.shouldLoadRelative = (referencedFile: string) => rRelativePath.test(referencedFile)
const prefixes = ['.' + sep, '..' + sep, './', '../']
this.shouldLoadRelative = (referencedFile: string) => prefixes.some(prefix => referencedFile.startsWith(prefix))
} else {
this.shouldLoadRelative = (_referencedFile: string) => false
}