From 3050a4424456f25d7e9d0c3c8df02daa0519a48d Mon Sep 17 00:00:00 2001 From: Richard Kuhnt Date: Sat, 15 Apr 2017 13:58:55 +0200 Subject: [PATCH] Fix hash detection and improve json path for arrays --- lib/autoupdate.ps1 | 15 ++++----------- lib/core.ps1 | 12 ++++++++++++ lib/json.ps1 | 9 +++++++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 58aca59b68..b1570f673d 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -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) { @@ -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) { @@ -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) { diff --git a/lib/core.ps1 b/lib/core.ps1 index 5df70dd6ef..754bdc1c05 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -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 +} \ No newline at end of file diff --git a/lib/json.ps1 b/lib/json.ps1 index a5189bc845..bbcb48f5a0 100644 --- a/lib/json.ps1 +++ b/lib/json.ps1 @@ -103,9 +103,14 @@ function json_path([Object] $json, [String] $jsonpath, [String] $basename) { return } - if($el -match "^(?\w+)\[(?\d+)\]$") { + # array detection + if($el -match "^(?\w+)\[(?[\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 }