fix(install.ps1): use ordinal IndexOf when stripping index URL credentials (#7286)
* fix(install.ps1): use ordinal IndexOf when stripping index URL credentials On non-English Windows locales, culture-aware String.IndexOf can mis-locate punctuation-only markers like ://, which corrupts scheme and authority parsing and crashes Remove-IndexUrlCredentials with a Substring ArgumentOutOfRangeException (issue 7279). Force Ordinal comparison for URL scheme/host parsing. Fixes #7279 * Condense the ordinal parsing comment in Remove-IndexUrlCredentials --------- Co-authored-by: Daniel Han <michaelhan2050@gmail.com>
This commit is contained in:
parent
2c492c8d9b
commit
5308c24e70
1 changed files with 5 additions and 3 deletions
|
|
@ -2030,16 +2030,18 @@ exit 0
|
|||
# _strip_index_url_credentials (install.sh / py / setup.ps1).
|
||||
function Remove-IndexUrlCredentials {
|
||||
param([string]$Url)
|
||||
$sep = $Url.IndexOf('://')
|
||||
# Ordinal, not culture-aware: on non-English locales (e.g. th-TH) linguistic
|
||||
# IndexOf treats "://" as ignorable, mis-locates it, and crashes Substring (issue #7279).
|
||||
$sep = $Url.IndexOf('://', [System.StringComparison]::Ordinal)
|
||||
if ($sep -lt 0) { return $Url }
|
||||
$scheme = $Url.Substring(0, $sep)
|
||||
$rest = $Url.Substring($sep + 3)
|
||||
# Drop query / fragment (may hold auth tokens).
|
||||
$q = $rest.IndexOfAny([char[]]('?', '#'))
|
||||
if ($q -ge 0) { $rest = $rest.Substring(0, $q) }
|
||||
$slash = $rest.IndexOf('/')
|
||||
$slash = $rest.IndexOf('/', [System.StringComparison]::Ordinal)
|
||||
$authority = if ($slash -ge 0) { $rest.Substring(0, $slash) } else { $rest }
|
||||
$at = $authority.LastIndexOf('@')
|
||||
$at = $authority.LastIndexOf('@', [System.StringComparison]::Ordinal)
|
||||
$host_ = if ($at -ge 0) { $authority.Substring($at + 1) } else { $authority }
|
||||
if ($slash -ge 0) { return "${scheme}://${host_}$($rest.Substring($slash))" }
|
||||
return "${scheme}://${host_}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue