Skip to content

Commit 4ebedae

Browse files
committed
```
fix(cursor-win-id-modifier): 修复PowerShell字符串插值中的变量解析问题 兼容PowerShell可展开字符串中"$var:"被当作作用域/驱动器前缀解析的问题, 改用"${var}"明确变量边界。同时修正了诊断信息中候选编号的字符串插值格式, 确保所有"$candidateNo"变量正确显示为数值而非空字符串。 ```
1 parent 3e0faf8 commit 4ebedae

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

scripts/run/cursor_win_id_modifier.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,38 +621,39 @@ function Modify-CursorJSFiles {
621621
Write-Host " $BLUEℹ$NC [方案B诊断] id.js偏移=$markerIndex | sha256 createHash 命中=$($hashMatches.Count)"
622622
$patched = $false
623623
$diagLines = @()
624+
# 兼容:PowerShell 可展开字符串中 "$var:" 会被当作作用域/驱动器前缀解析,需用 "${var}" 明确变量边界
624625
$candidateNo = 0
625626

626627
foreach ($hm in $hashMatches) {
627628
$candidateNo++
628629
$hashPos = $hm.Index
629630
$funcStart = $windowText.LastIndexOf("async function", $hashPos)
630631
if ($funcStart -lt 0) {
631-
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未找到 async function 起点" }
632+
if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 未找到 async function 起点" }
632633
continue
633634
}
634635

635636
$openBrace = $windowText.IndexOf("{", $funcStart)
636637
if ($openBrace -lt 0) {
637-
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未找到函数起始花括号" }
638+
if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 未找到函数起始花括号" }
638639
continue
639640
}
640641

641642
$endBrace = Find-JsMatchingBraceEnd -Text $windowText -OpenBraceIndex $openBrace -MaxScan 20000
642643
if ($endBrace -lt 0) {
643-
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 花括号配对失败(扫描上限内未闭合)" }
644+
if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 花括号配对失败(扫描上限内未闭合)" }
644645
continue
645646
}
646647

647648
$funcText = $windowText.Substring($funcStart, $endBrace - $funcStart + 1)
648649
if ($funcText.Length -gt 8000) {
649-
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 函数体过长 len=$($funcText.Length),已跳过" }
650+
if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 函数体过长 len=$($funcText.Length),已跳过" }
650651
continue
651652
}
652653

653654
$sig = [regex]::Match($funcText, '^async function (\w+)\((\w+)\)')
654655
if (-not $sig.Success) {
655-
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未解析到函数签名(async function name(param))" }
656+
if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 未解析到函数签名(async function name(param))" }
656657
continue
657658
}
658659
$fn = $sig.Groups[1].Value
@@ -662,7 +663,7 @@ function Modify-CursorJSFiles {
662663
$hasDigest = ($funcText -match '\.digest\(["'']hex["'']\)')
663664
$hasReturn = ($funcText -match ('return\s+' + [regex]::Escape($param) + '\?\w+:\w+\}'))
664665
if ($candidateNo -le 3) {
665-
$diagLines += "候选#$candidateNo: $fn($param) len=$($funcText.Length) digest=$hasDigest return=$hasReturn"
666+
$diagLines += "候选#${candidateNo}: $fn($param) len=$($funcText.Length) digest=$hasDigest return=$hasReturn"
666667
}
667668
if (-not $hasDigest) { continue }
668669
if (-not $hasReturn) { continue }
@@ -672,7 +673,7 @@ function Modify-CursorJSFiles {
672673
$absEnd = $markerIndex + $endBrace
673674
$content = $content.Substring(0, $absStart) + $replacement + $content.Substring($absEnd + 1)
674675

675-
Write-Host " $BLUEℹ$NC [方案B诊断] 命中候选#$candidateNo$fn($param) len=$($funcText.Length)"
676+
Write-Host " $BLUEℹ$NC [方案B诊断] 命中候选#${candidateNo}$fn($param) len=$($funcText.Length)"
676677
Write-Host " $GREEN$NC [方案B] 已重写 $fn($param) 机器码源函数(融合版特征匹配)"
677678
$replacedB6 = $true
678679
$patched = $true

0 commit comments

Comments
 (0)