Main: Change uri_ to url_ in encode functions and link URL spec

This commit is contained in:
networkException 2024-12-27 17:38:07 +01:00
parent 5b9f644db6
commit 5a5f6dcf05
Signed by: networkException
GPG key ID: E3877443AE684391

View file

@ -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://")))?;