mirror of
https://github.com/fosrl/pangolin.git
synced 2025-05-20 09:07:49 +01:00
parent
535b4e1fb1
commit
33ff2fbf3b
2 changed files with 29 additions and 8 deletions
|
@ -29,11 +29,6 @@ export function isValidUrlGlobPattern(pattern: string): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If segment contains *, it must be exactly *
|
|
||||||
if (segment.includes("*") && segment !== "*") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check each character in the segment
|
// Check each character in the segment
|
||||||
for (let j = 0; j < segment.length; j++) {
|
for (let j = 0; j < segment.length; j++) {
|
||||||
const char = segment[j];
|
const char = segment[j];
|
||||||
|
|
|
@ -534,7 +534,7 @@ async function checkRules(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPathAllowed(pattern: string, path: string): boolean {
|
export function isPathAllowed(pattern: string, path: string): boolean {
|
||||||
logger.debug(`\nMatching path "${path}" against pattern "${pattern}"`);
|
logger.debug(`\nMatching path "${path}" against pattern "${pattern}"`);
|
||||||
|
|
||||||
// Normalize and split paths into segments
|
// Normalize and split paths into segments
|
||||||
|
@ -575,7 +575,7 @@ function isPathAllowed(pattern: string, path: string): boolean {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For wildcards, try consuming different numbers of path segments
|
// For full segment wildcards, try consuming different numbers of path segments
|
||||||
if (currentPatternPart === "*") {
|
if (currentPatternPart === "*") {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Found wildcard at pattern index ${patternIndex}`
|
`${indent}Found wildcard at pattern index ${patternIndex}`
|
||||||
|
@ -607,6 +607,32 @@ function isPathAllowed(pattern: string, path: string): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for in-segment wildcard (e.g., "prefix*" or "prefix*suffix")
|
||||||
|
if (currentPatternPart.includes("*")) {
|
||||||
|
logger.debug(
|
||||||
|
`${indent}Found in-segment wildcard in "${currentPatternPart}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Convert the pattern segment to a regex pattern
|
||||||
|
const regexPattern = currentPatternPart
|
||||||
|
.replace(/\*/g, ".*") // Replace * with .* for regex wildcard
|
||||||
|
.replace(/\?/g, "."); // Replace ? with . for single character wildcard if needed
|
||||||
|
|
||||||
|
const regex = new RegExp(`^${regexPattern}$`);
|
||||||
|
|
||||||
|
if (regex.test(currentPathPart)) {
|
||||||
|
logger.debug(
|
||||||
|
`${indent}Segment with wildcard matches: "${currentPatternPart}" matches "${currentPathPart}"`
|
||||||
|
);
|
||||||
|
return matchSegments(patternIndex + 1, pathIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
`${indent}Segment with wildcard mismatch: "${currentPatternPart}" doesn't match "${currentPathPart}"`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// For regular segments, they must match exactly
|
// For regular segments, they must match exactly
|
||||||
if (currentPatternPart !== currentPathPart) {
|
if (currentPatternPart !== currentPathPart) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|
Loading…
Reference in a new issue