From 8300bbe45c0a7f3dcfa5463c26d617cd119b6514 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sun, 26 Jul 2026 10:48:57 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20a=20bug=20with=20did=20url?= =?UTF-8?q?=20parsing=20of=20fragments/queries.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/at/did.gleam | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/at/did.gleam b/src/at/did.gleam index b7635f9..c03679e 100644 --- a/src/at/did.gleam +++ b/src/at/did.gleam @@ -9,7 +9,6 @@ import gleam/int import gleam/json.{type Json} import gleam/list import gleam/option.{type Option, None, Some} -import gleam/result import gleam/string import gleam/uri.{type Uri, Uri} @@ -124,11 +123,7 @@ fn parse_web_host(host: String) -> Result(Did, Nil) { /// /// pub fn url_from_string(value: String) -> Result(Url, Nil) { - let #(authority, path) = - string.split_once(value, "/") - |> result.lazy_or(fn() { string.split_once(value, "?") }) - |> result.lazy_or(fn() { string.split_once(value, "#") }) - |> result.unwrap(#(value, "")) + let #(authority, path) = split_authority(value) case from_string(authority) { Ok(did) -> @@ -144,6 +139,21 @@ pub fn url_from_string(value: String) -> Result(Url, Nil) { } } +fn split_authority(value: String) -> #(String, String) { + case string.split_once(value, "/") { + Ok(#(authority, path)) -> #(authority, path) + Error(_) -> + case string.split_once(value, "?") { + Ok(#(authority, query)) -> #(authority, "?" <> query) + Error(_) -> + case string.split_once(value, "#") { + Ok(#(authority, fragment)) -> #(authority, "#" <> fragment) + Error(_) -> #(value, "") + } + } + } +} + fn parse_path(uri_string: String, url: Url) -> Result(Url, Nil) { do_parse_path(uri_string, uri_string, url, 0) } -- 2.51.2