From 5b8009dbd06f9a09065843de8eb5f8f680bb4f37 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Mon, 6 Jan 2020 17:08:59 +0100
Subject: Fix trailing / in URLs
Thanks to chacewells@gmail.com for reporting this issue.
---
META6.json | 5 +----
lib/URL.pm6 | 2 +-
lib/URL/Grammar.pm6 | 4 ++--
lib/URL/Grammar/Actions.pm6 | 2 +-
t/01-grammar.t | 20 +++++++++++++++++++-
5 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/META6.json b/META6.json
index 8d00433..46b4008 100644
--- a/META6.json
+++ b/META6.json
@@ -4,7 +4,6 @@
"Patrick Spek "
],
"depends": [
-
],
"description": "A Raku library to parse and handle URLs",
"license": "AGPL-3.0",
@@ -17,11 +16,9 @@
"URL::Grammar::Actions": "lib/URL/Grammar/Actions.pm6"
},
"resources": [
-
],
"source-url": "https://gitlab.com/tyil/raku-url",
"tags": [
-
],
- "version": "0.2.0"
+ "version": "0.2.1"
}
\ No newline at end of file
diff --git a/lib/URL.pm6 b/lib/URL.pm6
index fa9ebc8..113d902 100644
--- a/lib/URL.pm6
+++ b/lib/URL.pm6
@@ -139,7 +139,7 @@ multi method Str (
=NAME URL
=AUTHOR Patrick Spek
-=VERSION 0.2.0
+=VERSION 0.2.1
=head1 Synopsis
diff --git a/lib/URL/Grammar.pm6 b/lib/URL/Grammar.pm6
index 2f5cd45..e14f2a4 100644
--- a/lib/URL/Grammar.pm6
+++ b/lib/URL/Grammar.pm6
@@ -21,7 +21,7 @@ token password { <-[ @ ]>+ }
token host { [ ":" ]? }
token hostname { [ <-[ / : # ? \h ]>+ | "[" <-[ \] ]>+ "]" ] }
token port { \d ** 1..5 }
-token path { "/" * % "/" }
+token path { "/" * %% "/" }
token path-part { <-[ / ? # ]>+ }
token query { * % "&" }
token query-part { "=" }
@@ -33,7 +33,7 @@ token fragment { <-[ \s ]>+ }
=NAME URL::Grammar
=AUTHOR Patrick Spek
-=VERSION 0.2.0
+=VERSION 0.2.1
=head1 Synopsis
diff --git a/lib/URL/Grammar/Actions.pm6 b/lib/URL/Grammar/Actions.pm6
index 2ef70bb..be7dc4e 100644
--- a/lib/URL/Grammar/Actions.pm6
+++ b/lib/URL/Grammar/Actions.pm6
@@ -32,7 +32,7 @@ method fragment ($/) { make ~$/ }
=NAME URL::Grammar::Actions
=AUTHOR Patrick Spek
-=VERSION 0.2.0
+=VERSION 0.2.1
=head1 Synopsis
diff --git a/t/01-grammar.t b/t/01-grammar.t
index a84bf86..cf4e51f 100644
--- a/t/01-grammar.t
+++ b/t/01-grammar.t
@@ -5,7 +5,7 @@ use v6.d;
use URL::Grammar;
use Test;
-plan 2;
+plan 3;
subtest "https://www.tyil.nl", {
plan 8;
@@ -58,4 +58,22 @@ subtest "https://tyil:donthackme\@www.tyil.nl:8443/a/path/part?foo=bar&perl=6#mo
}
}
+subtest 'https://custom.endpoint/foo/bar/', {
+ plan 11;
+
+ my $match = URL::Grammar.parse('https://custom.endpoint/foo/bar/');
+
+ is ~$match, "https", "Scheme is 'https'";
+ nok $match, 'URL contains no username';
+ nok $match, 'URL contains no password';
+ is ~$match, 'custom.endpoint', "Hostname is 'custom.endpoint'";
+ nok $match, 'URL contains no port';
+ ok $match, 'URL contains a path';
+ is $match.elems, 2, 'Path contains 2 elements';
+ is ~$match[0], 'foo', 'Path part 0 is "foo"';
+ is ~$match[1], 'bar', 'Path part 0 is "bar"';
+ nok $match, 'URL contains no query';
+ nok $match, 'URL contains no fragment';
+}
+
# vim: ft=perl6 noet
--
cgit v1.1