Skip to content

Commit 2ec25ac

Browse files
Fix installed-font skip logic: use exact match + exclude known families from prefix scan
The previous prefix-only StartsWith check falsely marked fonts as installed when a different font family shared the same prefix (e.g., 'Roboto Condensed' installed would incorrectly skip 'Roboto'). Now uses a two-step approach: 1. Exact HashSet.Contains check (primary - O(1)) 2. Prefix fallback that excludes matches which are themselves known Google Font family names, preventing cross-family false positives
1 parent 2011e0e commit 2ec25ac

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/functions/public/Install-GoogleFont.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,24 @@ Please run the command again with elevated rights (Run as Administrator) or prov
112112
foreach ($n in $installedNames) {
113113
if ($n) { [void]$installedFamilies.Add($n) }
114114
}
115+
$knownFamilies = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
116+
foreach ($gf in $script:GoogleFonts) {
117+
[void]$knownFamilies.Add($gf.Name)
118+
}
115119
$toProcess = [System.Collections.Generic.List[object]]::new()
116120
foreach ($googleFont in $googleFontsToInstall) {
117121
$fontName = $googleFont.Name
118122
$skip = $false
119-
foreach ($family in $installedFamilies) {
120-
if ($family.StartsWith($fontName, [System.StringComparison]::OrdinalIgnoreCase)) { $skip = $true; break }
123+
if ($installedFamilies.Contains($fontName)) {
124+
$skip = $true
125+
} else {
126+
$prefix = "$fontName "
127+
foreach ($family in $installedFamilies) {
128+
if ($family.StartsWith($prefix, [System.StringComparison]::OrdinalIgnoreCase) -and
129+
-not $knownFamilies.Contains($family)) {
130+
$skip = $true; break
131+
}
132+
}
121133
}
122134
if ($skip) {
123135
Write-Verbose "[$fontName] - Already installed, skipping"

0 commit comments

Comments
 (0)