feat: Add path-only URI support

This commit is contained in:
ge 2022-05-16 23:56:20 +03:00
parent 37581ae961
commit bd616ba4fc
2 changed files with 57 additions and 0 deletions

View File

@ -90,6 +90,11 @@ parse_uri() {
if [[ "$uri" =~ :~/ ]]; then
path="~${path}"
fi
elif [[ "$scheme" == "$uri" ]] && [[ "$uri" =~ ^[./] ]]; then
# For URI with only Path component.
# Examples: /path ./path ../path ../../path
path="$uri"
scheme='file'
else
# For non authority component URI
path="$(<<< "$uri" sed "s/${scheme}://g")" || true

View File

@ -67,6 +67,58 @@ setup() {
[ "$fragment" == '' ]
}
@test "." {
. uri.sh
parse_uri '.'
[ "$scheme" == 'file' ]
[ "$hostname" == '' ]
[ "$port" == '' ]
[ "$path" == '.' ]
[ "$username" == '' ]
[ "$password" == '' ]
[ "$query" == '' ]
[ "$fragment" == '' ]
}
@test "./relative/path" {
. uri.sh
parse_uri './relative/path'
[ "$scheme" == 'file' ]
[ "$hostname" == '' ]
[ "$port" == '' ]
[ "$path" == './relative/path' ]
[ "$username" == '' ]
[ "$password" == '' ]
[ "$query" == '' ]
[ "$fragment" == '' ]
}
@test "../relative/path" {
. uri.sh
parse_uri '../relative/path'
[ "$scheme" == 'file' ]
[ "$hostname" == '' ]
[ "$port" == '' ]
[ "$path" == '../relative/path' ]
[ "$username" == '' ]
[ "$password" == '' ]
[ "$query" == '' ]
[ "$fragment" == '' ]
}
@test "/abs/path" {
. uri.sh
parse_uri '/abs/path'
[ "$scheme" == 'file' ]
[ "$hostname" == '' ]
[ "$port" == '' ]
[ "$path" == '/abs/path' ]
[ "$username" == '' ]
[ "$password" == '' ]
[ "$query" == '' ]
[ "$fragment" == '' ]
}
@test "sqlite:///path" {
. uri.sh
parse_uri 'sqlite:///path'