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'