Skip to content

Commit

Permalink
Fix hash detection and improve json path for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed Apr 15, 2017
1 parent 7fc0aa8 commit 3050a44
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 4 additions & 11 deletions lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function find_hash_in_rdf([String] $url, [String] $filename) {
# Find file content
$digest = $data.RDF.Content | ? { [String]$_.about -eq $filename }

return $digest.sha256
return format_hash $digest.sha256
}

function find_hash_in_textfile([String] $url, [String] $basename, [String] $regex) {
Expand Down Expand Up @@ -73,15 +73,7 @@ function find_hash_in_textfile([String] $url, [String] $basename, [String] $rege
}
}

switch ($hash.Length)
{
32 { $hash = "md5:$hash" } # md5
40 { $hash = "sha1:$hash" } # sha1
64 { $hash = $hash } # sha256
128 { $hash = "sha512:$hash" } # sha512
default { $hash = $null }
}
return $hash
return format_hash $hash
}

function find_hash_in_json([String] $url, [String] $basename, [String] $jsonpath) {
Expand All @@ -97,7 +89,8 @@ function find_hash_in_json([String] $url, [String] $basename, [String] $jsonpath
return
}

return json_path $json $jsonpath $basename
$hash = json_path $json $jsonpath $basename
return format_hash $hash
}

function get_hash_for_app([String] $app, $config, [String] $version, [String] $url, [Hashtable] $substitutions) {
Expand Down
12 changes: 12 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,15 @@ function get_app_with_version([String] $app) {
"version" = if ($version) { $version } else { 'latest' }
}
}

function format_hash([String] $hash) {
switch ($hash.Length)
{
32 { $hash = "md5:$hash" } # md5
40 { $hash = "sha1:$hash" } # sha1
64 { $hash = $hash } # sha256
128 { $hash = "sha512:$hash" } # sha512
default { $hash = $null }
}
return $hash
}
9 changes: 7 additions & 2 deletions lib/json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ function json_path([Object] $json, [String] $jsonpath, [String] $basename) {
return
}

if($el -match "^(?<property>\w+)\[(?<index>\d+)\]$") {
# array detection
if($el -match "^(?<property>\w+)\[(?<index>[\w\d.-]+)\]$") {
$property = $matches['property']
$result = $result.$property[$matches['index']]
if($matches['index'] -is [int]) {
$result = $result.$property[$matches['index']]
} else {
$result = $result.$property.($matches['index'])
}
return
}

Expand Down

0 comments on commit 3050a44

Please sign in to comment.