Skip to content

Commit

Permalink
fix: [#268] allow skipping validation
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick330602 committed Nov 12, 2023
1 parent 86cc1e5 commit c818f00
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
8 changes: 7 additions & 1 deletion docs/wslview.1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Component of WSL Utilities
.SH SYNOPSIS
.B wslview, wview, wslstart, wstart
.RB [ \-hvur ]
.RB [ \-hsvur ]
.PP
.B wslview, wview, wslstart, wstart
.I LINK/FILE
Expand All @@ -19,6 +19,9 @@ print a simple help.
.B -v, --version
print current version.
.TP
.B -s, --skip-validation-check
skip url validation check.
.TP
.B -u, --unreg-as-browser
remove \fBwslview\fR as the default WSL web browser.
.TP
Expand All @@ -35,6 +38,9 @@ cmd: use cmd.exe to start website/folder/file
cmd_explorer: use explorer.exe via cmd.exe to start website/folder/file
.in
.fi
.TP
.B WSLVIEW_SKIP_VALIDATION_CHECK
whether to skip validation check. Default is 1, which is not skipping. Can be either `0` or `1`.
.SH AUTHOR
Created by Patrick Wu <me@patrickwu.space>
.SH REPORTING BUGS
Expand Down
5 changes: 4 additions & 1 deletion src/etc/conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ WSLVAR_DEFAULT_VARTYPE=1
# powershell: use powershell.exe to start website/folder/file
# cmd: use cmd.exe to start website/folder/file
# cmd_explorer: use explorer.exe via cmd.exe to start website/folder/file
WSLVIEW_DEFAULT_ENGINE="powershell"
WSLVIEW_DEFAULT_ENGINE="powershell"

# wslview: whether to skip validation check. Default is 1, which is not skipping. Can be either `0` or `1`.
WSLVIEW_SKIP_VALIDATION_CHECK=1
5 changes: 4 additions & 1 deletion src/etc/user/conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
# powershell: use powershell.exe to start website/folder/file
# cmd: use cmd.exe to start website/folder/file
# cmd_explorer: use explorer.exe via cmd.exe to start website/folder/file
# WSLVIEW_DEFAULT_ENGINE="powershell"
# WSLVIEW_DEFAULT_ENGINE="powershell"

# wslview: whether to skip validation check. Default is 1, which is not skipping. Can be either `0` or `1`.
# WSLVIEW_SKIP_VALIDATION_CHECK=1
11 changes: 9 additions & 2 deletions src/wslview.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# shellcheck shell=bash
lname=""
skip_validation_check=${WSLVIEW_SKIP_VALIDATION_CHECK:-1}

help_short="$0 [-hvur]\n$0 [-E ENGINE] LINK/FILE"
help_short="$0 [-hsvur]\n$0 [-E ENGINE] LINK/FILE"

function del_reg_alt {
if [ "$distro" == "archlinux" ] || [ "$distro" == "alpine" ]; then
Expand Down Expand Up @@ -36,6 +37,7 @@ function url_validator {

while [ "$1" != "" ]; do
case "$1" in
-s|--skip-validation-check) skip_validation_check=0; shift;;
-r|--reg-as-browser) add_reg_alt;;
-u|--unreg-as-browser) del_reg_alt;;
-h|--help) help "$0" "$help_short"; exit;;
Expand Down Expand Up @@ -68,7 +70,12 @@ if [[ "$lname" != "" ]]; then
fi
debug_echo "properfile_full_path: $properfile_full_path"
debug_echo "validating whether if it is a link"
if (url_validator "$lname") && [ -z "$properfile_full_path" ]; then
is_valid_url=$(url_validator "$lname")
if [ "$skip_validation_check" -eq 0 ]; then
debug_echo "Skipping validation check"
is_valid_url=0
fi
if [[ "$is_valid_url" -eq 0 ]] && [ -z "$properfile_full_path" ]; then
debug_echo "It is a link"
cmd="\"$lname\""
elif [[ "$lname" =~ ^file:\/\/(\/)+[A-Za-z]\:.*$ ]] || [[ "$lname" =~ ^[A-Za-z]\:.*$ ]]; then
Expand Down
4 changes: 2 additions & 2 deletions tests/wslview.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ setup() {
@test "wslview - Help" {
run out/wslview --help
[ "${lines[0]}" = "wslview - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hvur\]$ ]]
[[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hsvur\]$ ]]
[[ "${lines[2]}" =~ ^.*wslview\ \[\-E\ ENGINE\]\ LINK/FILE$ ]]
}

@test "wslview - Help - Alt." {
run out/wslview -h
[ "${lines[0]}" = "wslview - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hvur\]$ ]]
[[ "${lines[1]}" =~ ^Usage\:\ .*wslview\ \[\-hsvur\]$ ]]
[[ "${lines[2]}" =~ ^.*wslview\ \[\-E\ ENGINE\]\ LINK/FILE$ ]]
}

Expand Down

0 comments on commit c818f00

Please sign in to comment.