aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gleam/uri.gleam5
-rw-r--r--test/gleam/uri_test.gleam12
2 files changed, 16 insertions, 1 deletions
diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam
index 8e49c5b..53c695a 100644
--- a/src/gleam/uri.gleam
+++ b/src/gleam/uri.gleam
@@ -237,7 +237,10 @@ if erlang {
/// ```
///
pub fn to_string(uri: Uri) -> String {
- let parts = []
+ let parts = case uri.fragment {
+ Some(fragment) -> ["#", fragment]
+ _ -> []
+ }
let parts = [uri.path, ..parts]
let parts = case uri.host, string.starts_with(uri.path, "/") {
Some(host), False if host != "" -> ["/", ..parts]
diff --git a/test/gleam/uri_test.gleam b/test/gleam/uri_test.gleam
index 46ac2a5..34c8a68 100644
--- a/test/gleam/uri_test.gleam
+++ b/test/gleam/uri_test.gleam
@@ -96,6 +96,10 @@ pub fn scheme_to_string_test() {
uri.Uri(Some("https"), None, None, None, "/one/two", None, None)
|> uri.to_string
|> should.equal("https:/one/two")
+
+ uri.Uri(None, None, None, None, "noslash", None, Some("frag"))
+ |> uri.to_string
+ |> should.equal("noslash#frag")
}
pub fn host_to_string_test() {
@@ -118,6 +122,14 @@ pub fn host_to_string_test() {
uri.Uri(None, None, Some(""), None, "", None, None)
|> uri.to_string
|> should.equal("//")
+
+ uri.Uri(None, None, Some("example.com"), None, "noslash", None, Some("ok"))
+ |> uri.to_string
+ |> should.equal("//example.com/noslash#ok")
+
+ uri.Uri(None, None, Some(""), None, "", None, Some("ok"))
+ |> uri.to_string
+ |> should.equal("//#ok")
}
pub fn port_to_string_test() {