Skip to content

Commit

Permalink
parse_app(): fix for relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed May 7, 2018
1 parent d0fa26e commit ff9c0c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,11 @@ function applist($apps, $global) {
return ,@($apps | ForEach-Object { ,@($_, $global) })
}

function parse_app($app) {
$app = [string]$app
if($app -notmatch '^((ht)|f)tps?://' -and $app -notmatch '^(?:[\w]\:\\|\\\\)') {
if($app -match '(?:(?<bucket>[a-zA-Z0-9-]+)\/)?(?<app>[a-zA-Z0-9-.]+)(?:@(?<version>.*))?') {
return $matches['app'], $matches['bucket'], $matches['version']
}
function parse_app([string] $app) {
if($app -match '(?:(?<bucket>[a-zA-Z0-9-]+)\/)?(?<app>.*.json$|[a-zA-Z0-9-.]+)(?:@(?<version>.*))?') {
return $matches['app'], $matches['bucket'], $matches['version']
}

$app, $null, $null
return $app, $null, $null
}

function last_scoop_update() {
Expand Down
24 changes: 24 additions & 0 deletions test/Scoop-Core.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ describe 'app' {
$bucket | should be $null
$version | should be $null

$query = "test.json"
$app, $bucket, $version = parse_app $query
$app | should be "test.json"
$bucket | should be $null
$version | should be $null

$query = ".\test.json"
$app, $bucket, $version = parse_app $query
$app | should be ".\test.json"
$bucket | should be $null
$version | should be $null

$query = "..\test.json"
$app, $bucket, $version = parse_app $query
$app | should be "..\test.json"
$bucket | should be $null
$version | should be $null

$query = "\\share\test.json"
$app, $bucket, $version = parse_app $query
$app | should be "\\share\test.json"
$bucket | should be $null
$version | should be $null

$query = "https://example.com/test.json"
$app, $bucket, $version = parse_app $query
$app | should be "https://example.com/test.json"
Expand Down

0 comments on commit ff9c0c3

Please sign in to comment.