Skip to content

Commit 21bf0de

Browse files
committed
Improve auto-update hash extraction regex
- Match only space and tab (\x20\t) instead of all whitespaces (\s) - Match only supported hash length (32 for md5 until 128 for sha512) - Ignores everything before the filename - Fixes a small bug where the last bit matched first digits from the next line but was not an issue because of non-capture group
1 parent 0646cc7 commit 21bf0de

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/autoupdate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function find_hash_in_textfile([String] $url, [String] $basename, [String] $rege
5555

5656
# find hash with filename in $hashfile (will be overridden by $regex)
5757
if ($hash.Length -eq 0 -and $regex.Length -eq 0) {
58-
$filenameRegex = "([a-fA-F0-9]+)\s+(?:\.\/|\*)?(?:`$basename)(\s[\d]+)?"
58+
$filenameRegex = "([a-fA-F0-9]{32,128})[\x20\t]+.*`$basename(?:[\x20\t]+\d+)?"
5959
$filenameRegex = substitute $filenameRegex @{'$basename' = [regex]::Escape($basename)}
6060
if ($hashfile -match $filenameRegex) {
6161
$hash = $matches[1]

0 commit comments

Comments
 (0)