Repository navigation
fix(leases): treat case aliases as overlapping write scopes #7252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JasonBuildAI
wants to merge
4
commits into
loopx-project:main
Choose a base branch
from
JasonBuildAI:codex/agent-z6k2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+330
−45
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a56b25
fix(leases): treat case aliases as overlapping write scopes
JasonBuildAI a710c6c
fix(leases): fold case within glob character classes
JasonBuildAI c398fbf
fix(leases): fold Unicode case aliases in write scopes
JasonBuildAI d9fdf99
fix(leases): fold Unicode case aliases inside glob character classes
JasonBuildAI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,52 +140,159 @@ function optionalInteger(value: unknown, label: string): number | null { | |
| return value; | ||
| } | ||
|
|
||
| function classMatch( | ||
| pattern: string, | ||
| start: number, | ||
| value: string, | ||
| ): { end: number; matches: boolean } | null { | ||
| const end = characterClassEnd(pattern, start); | ||
| if (end < 0) return null; | ||
| let body = pattern.slice(start + 1, end); | ||
| const negated = body.startsWith("!"); | ||
| if (negated) body = body.slice(1); | ||
| let matches = false; | ||
| /** Host case aliases include Unicode folds whose length changes, such as ß -> ss. */ | ||
| function caseFold(value: string): string { | ||
| return value.toUpperCase().toLowerCase(); | ||
| } | ||
|
|
||
| type GlobToken = | ||
| | {kind: "literal"; literal: string; folded: string} | ||
| | {kind: "star"} | ||
| | {kind: "question"} | ||
| | {kind: "class"; body: string; negated: boolean}; | ||
|
|
||
| function globTokens(pattern: string): GlobToken[] { | ||
| const tokens: GlobToken[] = []; | ||
| let literal = ""; | ||
| const flushLiteral = () => { | ||
| if (literal.length === 0) return; | ||
| tokens.push({kind: "literal", literal, folded: caseFold(literal)}); | ||
| literal = ""; | ||
| }; | ||
| for (let index = 0; index < pattern.length; index += 1) { | ||
| const character = pattern[index]; | ||
| if (character === "*") { | ||
| flushLiteral(); | ||
| tokens.push({kind: "star"}); | ||
| continue; | ||
| } | ||
| if (character === "?") { | ||
| flushLiteral(); | ||
| tokens.push({kind: "question"}); | ||
| continue; | ||
| } | ||
| if (character === "[") { | ||
| const end = characterClassEnd(pattern, index); | ||
| if (end >= 0) { | ||
| flushLiteral(); | ||
| let body = pattern.slice(index + 1, end); | ||
| const negated = body.startsWith("!"); | ||
| if (negated) body = body.slice(1); | ||
| tokens.push({kind: "class", body, negated}); | ||
| index = end; | ||
| continue; | ||
| } | ||
| } | ||
| literal += character; | ||
| } | ||
| flushLiteral(); | ||
| return tokens; | ||
| } | ||
|
|
||
| type CharacterClass = { | ||
| literals: readonly string[]; | ||
| ranges: readonly (readonly [string, string])[]; | ||
| }; | ||
|
|
||
| function characterClass(body: string): CharacterClass { | ||
| const literals: string[] = []; | ||
| const ranges: Array<readonly [string, string]> = []; | ||
| for (let index = 0; index < body.length; index += 1) { | ||
| if (index + 2 < body.length && body[index + 1] === "-") { | ||
| if (body[index] <= value && value <= body[index + 2]) matches = true; | ||
| ranges.push([body[index], body[index + 2]]); | ||
| index += 2; | ||
| } else if (body[index] === value) { | ||
| matches = true; | ||
| } else { | ||
| literals.push(body[index]); | ||
| } | ||
| } | ||
| return { end, matches: negated ? !matches : matches }; | ||
| return {literals, ranges}; | ||
| } | ||
|
|
||
| function fnmatchcase(value: string, pattern: string): boolean { | ||
| /** Single-character case variants, so a range keeps its original interval. */ | ||
| function singleCharacterVariants(value: string): string[] { | ||
| const variants = new Set<string>(); | ||
| for (const candidate of [value, value.toLowerCase(), value.toUpperCase(), caseFold(value)]) { | ||
| if ([...candidate].length === 1) variants.add(candidate); | ||
| } | ||
| return [...variants]; | ||
| } | ||
|
|
||
| /** | ||
| * Class membership is a symmetric fold equivalence: a member and the compared text | ||
| * match when their canonical fold is equal. That covers non-reciprocal Unicode | ||
| * aliases (a class member ς against Σ) and folds that change length (ß against SS). | ||
| * Ranges keep their original interval and only ever consume one unit. | ||
| */ | ||
| function classMemberMatches(body: string, candidate: string, foldCase: boolean): boolean { | ||
| const {literals, ranges} = characterClass(body); | ||
| const folded = foldCase ? caseFold(candidate) : candidate; | ||
| for (const literal of literals) { | ||
| if (literal === candidate || (foldCase && caseFold(literal) === folded)) return true; | ||
| } | ||
| if ([...candidate].length !== 1) return false; | ||
| for (const [low, high] of ranges) { | ||
| for (const variant of (foldCase ? singleCharacterVariants(candidate) : [candidate])) { | ||
| if (low <= variant && variant <= high) return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * A class consumes one unit by default. Case folding may consume several when the | ||
| * compared text folds to the same string as a member (ß/SS, ffi/FFI). | ||
| */ | ||
| function classMatchLengths(body: string, value: string, start: number, foldCase: boolean): number[] { | ||
| const lengths: number[] = []; | ||
| const maximum = foldCase ? 3 : 1; | ||
| for (let length = 1; length <= maximum && start + length <= value.length; length += 1) { | ||
| if (classMemberMatches(body, value.slice(start, start + length), foldCase)) { | ||
| lengths.push(length); | ||
| } | ||
| } | ||
| return lengths; | ||
| } | ||
|
|
||
| function fnmatchcase(value: string, pattern: string, foldCase = false): boolean { | ||
| const tokens = globTokens(pattern); | ||
| const memo = new Map<string, boolean>(); | ||
| const match = (valueIndex: number, patternIndex: number): boolean => { | ||
| const key = `${valueIndex}:${patternIndex}`; | ||
| const match = (valueIndex: number, tokenIndex: number): boolean => { | ||
| const key = `${valueIndex}:${tokenIndex}`; | ||
| const cached = memo.get(key); | ||
| if (cached !== undefined) return cached; | ||
| let result: boolean; | ||
| if (patternIndex === pattern.length) { | ||
| if (tokenIndex === tokens.length) { | ||
| result = valueIndex === value.length; | ||
| } else if (pattern[patternIndex] === "*") { | ||
| result = match(valueIndex, patternIndex + 1) || | ||
| (valueIndex < value.length && match(valueIndex + 1, patternIndex)); | ||
| } else if (valueIndex === value.length) { | ||
| result = false; | ||
| } else if (pattern[patternIndex] === "?") { | ||
| result = match(valueIndex + 1, patternIndex + 1); | ||
| } else if (pattern[patternIndex] === "[") { | ||
| const characterClass = classMatch(pattern, patternIndex, value[valueIndex]); | ||
| result = characterClass === null | ||
| ? value[valueIndex] === "[" && match(valueIndex + 1, patternIndex + 1) | ||
| : characterClass.matches && match(valueIndex + 1, characterClass.end + 1); | ||
| } else { | ||
| result = value[valueIndex] === pattern[patternIndex] && | ||
| match(valueIndex + 1, patternIndex + 1); | ||
| const token = tokens[tokenIndex]; | ||
| if (token.kind === "star") { | ||
| result = match(valueIndex, tokenIndex + 1) || | ||
| (valueIndex < value.length && match(valueIndex + 1, tokenIndex)); | ||
| } else if (valueIndex === value.length) { | ||
| result = false; | ||
| } else if (token.kind === "question") { | ||
| result = match(valueIndex + 1, tokenIndex + 1); | ||
| } else if (token.kind === "class") { | ||
| // Negation applies after the union of every fold-equivalent candidate. | ||
| const lengths = classMatchLengths(token.body, value, valueIndex, foldCase); | ||
| result = token.negated | ||
| ? lengths.length === 0 && match(valueIndex + 1, tokenIndex + 1) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] 任意长候选会压掉合法负类续接。 |
||
| : lengths.some((length) => match(valueIndex + length, tokenIndex + 1)); | ||
| } else { | ||
| result = false; | ||
| for (let end = valueIndex + 1; end <= value.length; end += 1) { | ||
| const candidate = value.slice(valueIndex, end); | ||
| const folded = caseFold(candidate); | ||
| if (foldCase ? folded.length > token.folded.length : candidate.length > token.literal.length) { | ||
| break; | ||
| } | ||
| if ((foldCase ? folded === token.folded : candidate === token.literal) && | ||
| match(end, tokenIndex + 1)) { | ||
| result = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| memo.set(key, result); | ||
| return result; | ||
|
|
@@ -201,32 +308,34 @@ function scopeLiteralPrefix(scope: string): string { | |
| } | ||
|
|
||
| function scopePairOverlaps(left: string, right: string): boolean { | ||
| if (left === right) return true; | ||
| const equal = (first: string, second: string) => first === second || | ||
| caseFold(first) === caseFold(second); | ||
| if (equal(left, right)) return true; | ||
| if (["*", "**", "./"].includes(left) || ["*", "**", "./"].includes(right)) { | ||
| return true; | ||
| } | ||
| const leftGlob = ["*", "?", "["].some((token) => left.includes(token)); | ||
| const rightGlob = ["*", "?", "["].some((token) => right.includes(token)); | ||
| if (leftGlob && !rightGlob) { | ||
| const prefix = scopeLiteralPrefix(left); | ||
| return fnmatchcase(right, left) || | ||
| (prefix.endsWith("/") && right.replace(/\/$/u, "") === prefix.replace(/\/$/u, "")); | ||
| return fnmatchcase(right, left, true) || | ||
| (prefix.endsWith("/") && equal(right.replace(/\/$/u, ""), prefix.replace(/\/$/u, ""))); | ||
| } | ||
| if (rightGlob && !leftGlob) { | ||
| const prefix = scopeLiteralPrefix(right); | ||
| return fnmatchcase(left, right) || | ||
| (prefix.endsWith("/") && left.replace(/\/$/u, "") === prefix.replace(/\/$/u, "")); | ||
| return fnmatchcase(left, right, true) || | ||
| (prefix.endsWith("/") && equal(left.replace(/\/$/u, ""), prefix.replace(/\/$/u, ""))); | ||
| } | ||
| if (leftGlob && rightGlob) { | ||
| const leftPrefix = scopeLiteralPrefix(left); | ||
| const rightPrefix = scopeLiteralPrefix(right); | ||
| const leftPrefix = caseFold(scopeLiteralPrefix(left)); | ||
| const rightPrefix = caseFold(scopeLiteralPrefix(right)); | ||
| return !leftPrefix || !rightPrefix || leftPrefix.startsWith(rightPrefix) || | ||
| rightPrefix.startsWith(leftPrefix); | ||
| } | ||
| const leftRoot = left.replace(/\/$/u, ""); | ||
| const rightRoot = right.replace(/\/$/u, ""); | ||
| return (left.endsWith("/") && right.startsWith(`${leftRoot}/`)) || | ||
| (right.endsWith("/") && left.startsWith(`${rightRoot}/`)); | ||
| const leftRoot = caseFold(left.replace(/\/$/u, "")); | ||
| const rightRoot = caseFold(right.replace(/\/$/u, "")); | ||
| return (left.endsWith("/") && caseFold(right).startsWith(`${leftRoot}/`)) || | ||
| (right.endsWith("/") && caseFold(left).startsWith(`${rightRoot}/`)); | ||
| } | ||
|
|
||
| function writeScopesOverlap(left: readonly string[], right: readonly string[]): boolean { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] 单元素 Unicode 区间仍漏判同文件别名。
src/[ς-ς].ts→src/Σ.ts、src/[ß-ß].ts→src/SS.ts在 File/SQLite acquire 与原子 claim 共 8 例均准入两份 active 独占租约并修改 provider;原生 glob 与同文件检查独立确认覆盖。普通字符类虽已修复,range 仍只枚举输入单字符变体且拒绝变长候选。请在同一 matcher 补齐区间成员对称 fold 与消费长度,保留原 scope/请求身份;加入两 provider、两入口的拒绝不写状态及否定区间控制。