Skip to content

Commit bf02470

Browse files
committed
search: better handling for invalid query (fixes #634
1 parent c98e8b6 commit bf02470

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

libexec/scoop-search.ps1

+14-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ function search_bucket($bucket, $query) {
2929
@{ name = $_ }
3030
}
3131

32-
if($query) { $apps = $apps | ? {
33-
if($_.name -match $query) { return $true }
34-
$bin = bin_match (manifest $_.name $bucket) $query
35-
if($bin) {
36-
$_.bin = $bin; return $true;
32+
if($query) {
33+
try {
34+
$query = new-object regex $query
35+
} catch {
36+
abort "invalid regular expression: $($_.exception.innerexception.message)"
3737
}
38-
} }
38+
39+
$apps = $apps | ? {
40+
if($_.name -match $query) { return $true }
41+
$bin = bin_match (manifest $_.name $bucket) $query
42+
if($bin) {
43+
$_.bin = $bin; return $true;
44+
}
45+
}
46+
}
3947
$apps | % { $_.version = (latest_version $_.name $bucket); $_ }
4048
}
4149

0 commit comments

Comments
 (0)