fix: permissions wildcarding so that for ex: 'ls *' includes ls * AND 'ls' to prevent having to double state commands or use 'ls*'

This commit is contained in:
Aiden Cline
2026-01-12 13:02:29 -06:00
parent 22c68a6992
commit 62702fbd11
2 changed files with 32 additions and 10 deletions

View File

@@ -2,16 +2,18 @@ import { sortBy, pipe } from "remeda"
export namespace Wildcard {
export function match(str: string, pattern: string) {
const regex = new RegExp(
"^" +
pattern
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // escape special regex chars
.replace(/\*/g, ".*") // * becomes .*
.replace(/\?/g, ".") + // ? becomes .
"$",
"s", // s flag enables multiline matching
)
return regex.test(str)
let escaped = pattern
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // escape special regex chars
.replace(/\*/g, ".*") // * becomes .*
.replace(/\?/g, ".") // ? becomes .
// If pattern ends with " *" (space + wildcard), make the trailing part optional
// This allows "ls *" to match both "ls" and "ls -la"
if (escaped.endsWith(" .*")) {
escaped = escaped.slice(0, -3) + "( .*)?"
}
return new RegExp("^" + escaped + "$", "s").test(str)
}
export function all(input: string, patterns: Record<string, any>) {