From 5a5f6dcf0564b36a9a1a1af5176702c3fe884ca9 Mon Sep 17 00:00:00 2001 From: networkException Date: Fri, 27 Dec 2024 17:38:07 +0100 Subject: [PATCH] Main: Change uri_ to url_ in encode functions and link URL spec --- src/main.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index dfb7da5..7984e02 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,24 +48,27 @@ fn main() -> Result<()> { data_map.insert(secret_key.to_string(), Value::String(secret_value.trim().to_string())); } - handlebars.register_helper("uri_encode_user_info", Box::new(|helper: &Helper, _: &Handlebars, _: &Context, _: &mut RenderContext, out: &mut dyn Output| -> HelperResult { - let parameter = helper.param(0).ok_or(RenderErrorReason::ParamNotFoundForIndex("uri_encode_user_info", 0))?; + // NOTE: See https://url.spec.whatwg.org/#userinfo-percent-encode-set + handlebars.register_helper("url_encode_user_info", Box::new(|helper: &Helper, _: &Handlebars, _: &Context, _: &mut RenderContext, out: &mut dyn Output| -> HelperResult { + let parameter = helper.param(0).ok_or(RenderErrorReason::ParamNotFoundForIndex("url_encode_user_info", 0))?; let parameter_value = parameter.value().render(); out.write(url_escape::encode_userinfo_to_string(parameter_value, &mut String::from("https://")))?; Ok(()) })); - handlebars.register_helper("uri_encode_path", Box::new(|helper: &Helper, _: &Handlebars, _: &Context, _: &mut RenderContext, out: &mut dyn Output| -> HelperResult { - let parameter = helper.param(0).ok_or(RenderErrorReason::ParamNotFoundForIndex("uri_encode_path", 0))?; + // NOTE: See https://url.spec.whatwg.org/#path-percent-encode-set + handlebars.register_helper("url_encode_path", Box::new(|helper: &Helper, _: &Handlebars, _: &Context, _: &mut RenderContext, out: &mut dyn Output| -> HelperResult { + let parameter = helper.param(0).ok_or(RenderErrorReason::ParamNotFoundForIndex("url_encode_path", 0))?; let parameter_value = parameter.value().render(); out.write(url_escape::encode_path_to_string(parameter_value, &mut String::from("https://")))?; Ok(()) })); - handlebars.register_helper("uri_encode_component", Box::new(|helper: &Helper, _: &Handlebars, _: &Context, _: &mut RenderContext, out: &mut dyn Output| -> HelperResult { - let parameter = helper.param(0).ok_or(RenderErrorReason::ParamNotFoundForIndex("uri_encode_component", 0))?; + // NOTE: See https://url.spec.whatwg.org/#component-percent-encode-set + handlebars.register_helper("url_encode_component", Box::new(|helper: &Helper, _: &Handlebars, _: &Context, _: &mut RenderContext, out: &mut dyn Output| -> HelperResult { + let parameter = helper.param(0).ok_or(RenderErrorReason::ParamNotFoundForIndex("url_encode_component", 0))?; let parameter_value = parameter.value().render(); out.write(url_escape::encode_component_to_string(parameter_value, &mut String::from("https://")))?;