Skip to content

Commit ff9c0c3

Browse files
committed
parse_app(): fix for relative paths
1 parent d0fa26e commit ff9c0c3

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

lib/core.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,11 @@ function applist($apps, $global) {
494494
return ,@($apps | ForEach-Object { ,@($_, $global) })
495495
}
496496

497-
function parse_app($app) {
498-
$app = [string]$app
499-
if($app -notmatch '^((ht)|f)tps?://' -and $app -notmatch '^(?:[\w]\:\\|\\\\)') {
500-
if($app -match '(?:(?<bucket>[a-zA-Z0-9-]+)\/)?(?<app>[a-zA-Z0-9-.]+)(?:@(?<version>.*))?') {
501-
return $matches['app'], $matches['bucket'], $matches['version']
502-
}
497+
function parse_app([string] $app) {
498+
if($app -match '(?:(?<bucket>[a-zA-Z0-9-]+)\/)?(?<app>.*.json$|[a-zA-Z0-9-.]+)(?:@(?<version>.*))?') {
499+
return $matches['app'], $matches['bucket'], $matches['version']
503500
}
504-
505-
$app, $null, $null
501+
return $app, $null, $null
506502
}
507503

508504
function last_scoop_update() {

test/Scoop-Core.Tests.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,30 @@ describe 'app' {
223223
$bucket | should be $null
224224
$version | should be $null
225225

226+
$query = "test.json"
227+
$app, $bucket, $version = parse_app $query
228+
$app | should be "test.json"
229+
$bucket | should be $null
230+
$version | should be $null
231+
232+
$query = ".\test.json"
233+
$app, $bucket, $version = parse_app $query
234+
$app | should be ".\test.json"
235+
$bucket | should be $null
236+
$version | should be $null
237+
238+
$query = "..\test.json"
239+
$app, $bucket, $version = parse_app $query
240+
$app | should be "..\test.json"
241+
$bucket | should be $null
242+
$version | should be $null
243+
244+
$query = "\\share\test.json"
245+
$app, $bucket, $version = parse_app $query
246+
$app | should be "\\share\test.json"
247+
$bucket | should be $null
248+
$version | should be $null
249+
226250
$query = "https://example.com/test.json"
227251
$app, $bucket, $version = parse_app $query
228252
$app | should be "https://example.com/test.json"

0 commit comments

Comments
 (0)