From bd616ba4fcd9bdf6f0bb32cf98794e235b10f242 Mon Sep 17 00:00:00 2001 From: ge Date: Mon, 16 May 2022 23:56:20 +0300 Subject: [PATCH] feat: Add path-only URI support --- src/lib/uri.sh | 5 +++++ tests/parse_uri.bats | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/lib/uri.sh b/src/lib/uri.sh index 5778ff4..784c5b4 100644 --- a/src/lib/uri.sh +++ b/src/lib/uri.sh @@ -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 diff --git a/tests/parse_uri.bats b/tests/parse_uri.bats index 4430111..e50c016 100644 --- a/tests/parse_uri.bats +++ b/tests/parse_uri.bats @@ -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'