From 4fec03a49d18f2d1f4239c96460df1ef4174660d Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Tue, 30 Jul 2024 08:17:51 +0100 Subject: [PATCH 1/7] Add Uri.empty constant representing an empty URI, equivalent to "" --- src/gleam/uri.gleam | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index b64a1c09..8244280d 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -28,6 +28,33 @@ pub type Uri { ) } +/// Constant representing an empty URI, equivalent to "". +/// +/// ## Examples +/// +/// ```gleam +/// let uri = Uri(..Uri.empty, scheme: Some("https"), host: Some("example.com")) +/// // -> Uri( +/// // scheme: Some("https"), +/// // userinfo: None, +/// // host: Some("example.com"), +/// // port: None, +/// // path: "", +/// // query: None, +/// // fragment: None, +/// // ) +/// ``` +/// +pub const empty = Uri( + scheme: None, + userinfo: None, + host: None, + port: None, + path: "", + query: None, + fragment: None, +) + /// Parses a compliant URI string into the `Uri` Type. /// If the string is not a valid URI string then an error is returned. /// From d1cb48bcf4cdf20f6d4afd67cc0080e651dd26ea Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Thu, 8 Aug 2024 19:31:42 +0100 Subject: [PATCH 2/7] Refactor Uri.to_string function example to use Uri.empty constant --- src/gleam/uri.gleam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index 8244280d..6ada5dfe 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -647,7 +647,7 @@ fn remove_dot_segments_loop( /// ## Examples /// /// ```gleam -/// let uri = Uri(Some("http"), None, Some("example.com"), ...) +/// let uri = Uri(..Uri.empty, scheme: Some("http"), host: Some("example.com")) /// to_string(uri) /// // -> "http://example.com" /// ``` From 64ffea961f185e138a18c84c9e6e503b6c14e70d Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Thu, 2 Jan 2025 22:27:29 +0100 Subject: [PATCH 3/7] Refactor Uri.parse function to use Uri.empty constant --- src/gleam/uri.gleam | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index 6ada5dfe..866bf186 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -85,18 +85,7 @@ pub fn parse(uri_string: String) -> Result(Uri, Nil) { // TODO: This is not perfect and will be more permissive than its Erlang // counterpart, ideally we want to replicate Erlang's implementation on the js // target as well. - let default_pieces = - Uri( - scheme: None, - userinfo: None, - host: None, - port: None, - path: "", - query: None, - fragment: None, - ) - - parse_scheme_loop(uri_string, uri_string, default_pieces, 0) + parse_scheme_loop(uri_string, uri_string, empty, 0) } fn parse_scheme_loop( From 339b223c07c0bcdf80ae27ed3d0e041c95e73da3 Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Wed, 8 Jan 2025 23:36:47 +0100 Subject: [PATCH 4/7] Refactor Uri module examples to use https --- src/gleam/uri.gleam | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index 866bf186..a252aa2f 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -636,9 +636,9 @@ fn remove_dot_segments_loop( /// ## Examples /// /// ```gleam -/// let uri = Uri(..Uri.empty, scheme: Some("http"), host: Some("example.com")) +/// let uri = Uri(..Uri.empty, scheme: Some("https"), host: Some("example.com")) /// to_string(uri) -/// // -> "http://example.com" +/// // -> "https://example.com" /// ``` /// pub fn to_string(uri: Uri) -> String { @@ -680,9 +680,9 @@ pub fn to_string(uri: Uri) -> String { /// ## Examples /// /// ```gleam -/// let assert Ok(uri) = parse("http://example.com/path?foo#bar") +/// let assert Ok(uri) = parse("https://example.com/path?foo#bar") /// origin(uri) -/// // -> Ok("http://example.com") +/// // -> Ok("https://example.com") /// ``` /// pub fn origin(uri: Uri) -> Result(String, Nil) { From 863232667e974e421b2ef6e781f66e18894c0584 Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Sun, 9 Feb 2025 10:55:02 +0100 Subject: [PATCH 5/7] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c1b6945..f88e7ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fixed a bug that would result in `list.unique` having quadratic runtime. - Fixed the implementation of `list.key_set` to be tail recursive. - The `pop` and `pop_map` functions in the `list` module have been deprecated. +- Added `Uri.empty` constant representing an empty URI, equivalent to `""`. ## v0.53.0 - 2025-01-23 From 7867831eb1d235d51bd0247790187dca7c3f730c Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Tue, 11 Feb 2025 00:40:11 +0100 Subject: [PATCH 6/7] Change Uri.empty examples to not use Uri module prefix --- src/gleam/uri.gleam | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index a252aa2f..5b6565cc 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -33,7 +33,7 @@ pub type Uri { /// ## Examples /// /// ```gleam -/// let uri = Uri(..Uri.empty, scheme: Some("https"), host: Some("example.com")) +/// let uri = Uri(..empty, scheme: Some("https"), host: Some("example.com")) /// // -> Uri( /// // scheme: Some("https"), /// // userinfo: None, @@ -636,7 +636,7 @@ fn remove_dot_segments_loop( /// ## Examples /// /// ```gleam -/// let uri = Uri(..Uri.empty, scheme: Some("https"), host: Some("example.com")) +/// let uri = Uri(..empty, scheme: Some("https"), host: Some("example.com")) /// to_string(uri) /// // -> "https://example.com" /// ``` From 1351e789511ecab41d973ec967cea223e6a128a0 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 11 Feb 2025 11:56:01 +0000 Subject: [PATCH 7/7] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f88e7ca3..008d5043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - Fixed a bug that would result in `list.unique` having quadratic runtime. - Fixed the implementation of `list.key_set` to be tail recursive. - The `pop` and `pop_map` functions in the `list` module have been deprecated. -- Added `Uri.empty` constant representing an empty URI, equivalent to `""`. +- The `uri` module gains the `empty` value, representing an empty URI which + equivalent to `""`. ## v0.53.0 - 2025-01-23