diff --git a/src/gluri/internal/parser.gleam b/src/gluri/internal/parser.gleam index ab53448..253b2df 100644 --- a/src/gluri/internal/parser.gleam +++ b/src/gluri/internal/parser.gleam @@ -168,7 +168,7 @@ fn parse_authority(str: String) -> Result(#(Uri, String), Nil) { } fn parse_authority_part(str: String) -> Result(#(Uri, String), Nil) { - let #(userinfo, rest) = parse_userinfo(str, "") + let #(userinfo, rest) = parse_userinfo(str) use #(host, rest) <- result.try(parse_host(rest)) @@ -180,8 +180,12 @@ fn parse_authority_part(str: String) -> Result(#(Uri, String), Nil) { } // userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) -fn parse_userinfo(str: String, userinfo: String) -> #(Option(String), String) { +fn parse_userinfo(str: String) -> #(Option(String), String) { use <- bool.guard(when: !string.contains(str, "@"), return: #(None, str)) + do_parse_userinfo(str, "") +} + +fn do_parse_userinfo(str: String, userinfo: String) -> #(Option(String), String) { case str { "@" <> rest -> #(Some(userinfo), rest) "" -> #(None, userinfo <> str) @@ -202,7 +206,7 @@ fn parse_userinfo(str: String, userinfo: String) -> #(Option(String), String) { str, ) { - Ok(#(part, rest)) -> parse_userinfo(rest, userinfo <> part) + Ok(#(part, rest)) -> do_parse_userinfo(rest, userinfo <> part) Error(_) -> #(None, userinfo <> str) } } @@ -421,7 +425,7 @@ fn parse_ipv4address(str: String) { // / "1" 2DIGIT ; 100-199 // / "2" %x30-34 DIGIT ; 200-249 // / "25" %x30-35 ; 250-255 -pub fn parse_dec_octet(str: String) -> Result(#(String, String), Nil) { +fn parse_dec_octet(str: String) -> Result(#(String, String), Nil) { try_parsers( [ parse_this_then(_, [ @@ -486,7 +490,7 @@ pub fn parse_dec_octet(str: String) -> Result(#(String, String), Nil) { } // reg-name = *( unreserved / pct-encoded / sub-delims ) -pub fn parse_reg_name(str: String) { +fn parse_reg_name(str: String) { // can't error case do_parse_reg_name(str, "") { diff --git a/test/benchmark.gleam b/test/benchmark.gleam index 7b6ac06..de54e39 100644 --- a/test/benchmark.gleam +++ b/test/benchmark.gleam @@ -1,6 +1,5 @@ import gleam/uri as uri2 import gluri as uri -import gluri/internal/parser import glychee/benchmark import glychee/configuration @@ -15,43 +14,43 @@ pub fn main() { // ip_benchmark() } -@target(erlang) -pub fn ip_benchmark() { - benchmark.run( - [ - benchmark.Function("ip_benchmark", fn(data) { - fn() { - let _ = parser.parse_dec_octet(data) - Nil - } - }), - ], - [ - benchmark.Data("173", "173"), - benchmark.Data("5", "5"), - benchmark.Data("200", "200"), - benchmark.Data("255", "255"), - benchmark.Data("fail", "2b"), - ], - ) -} +// @target(erlang) +// pub fn ip_benchmark() { +// benchmark.run( +// [ +// benchmark.Function("ip_benchmark", fn(data) { +// fn() { +// let _ = parser.parse_dec_octet(data) +// Nil +// } +// }), +// ], +// [ +// benchmark.Data("173", "173"), +// benchmark.Data("5", "5"), +// benchmark.Data("200", "200"), +// benchmark.Data("255", "255"), +// benchmark.Data("fail", "2b"), +// ], +// ) +// } -@target(erlang) -pub fn reg_name_benchmark() { - benchmark.run( - [ - benchmark.Function("reg_name_benchmark", fn(data) { - fn() { - let _ = parser.parse_reg_name(data) - Nil - } - }), - ], - [ - benchmark.Data("long", "github.com"), - ], - ) -} +// @target(erlang) +// pub fn reg_name_benchmark() { +// benchmark.run( +// [ +// benchmark.Function("reg_name_benchmark", fn(data) { +// fn() { +// let _ = parser.parse_reg_name(data) +// Nil +// } +// }), +// ], +// [ +// benchmark.Data("long", "github.com"), +// ], +// ) +// } @target(erlang) pub fn parse_benchmark() { @@ -75,6 +74,10 @@ pub fn parse_benchmark() { "long", "https://github.com/gleam-lang/stdlib/issues/523#issuecomment-3288230480", ), + benchmark.Data( + "with user", + "https://test_name:user%20$$$@github.com/gleam-lang/stdlib/issues/523#issuecomment-3288230480", + ), benchmark.Data("ipv4", "https://192.255.36.4/"), ], )