Skip to content

Commit

Permalink
Improve auto-update hash extraction regex
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
r15ch13 committed Mar 18, 2018
1 parent 0646cc7 commit 21bf0de
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function find_hash_in_textfile([String] $url, [String] $basename, [String] $rege

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

0 comments on commit 21bf0de

Please sign in to comment.