From 2e3e49f880bac4fcf66c7a9da73947250847fef7 Mon Sep 17 00:00:00 2001 From: Jose Quintana <1700322+joseluisq@users.noreply.github.com> Date: Tue, 19 Sep 2023 06:41:24 +0200 Subject: [PATCH] fix: rewrites/redirects do not capture glob groups correctly (#265) by removing the non-capturing group that appeared during the glob to regex conversion. the following glob example works now ```toml [advanced] [[advanced.rewrites]] source = "/files/{*}" destination = "/$1" ``` --- src/settings/mod.rs | 16 ++++++++++++---- tests/toml/config.toml | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 0429bee..39023b2 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -342,8 +342,12 @@ impl Settings { })? .compile_matcher(); - let pattern = - source.glob().regex().trim_start_matches("(?-u)").to_owned(); + let pattern = source + .glob() + .regex() + .trim_start_matches("(?-u)") + .replace("?:.*", ".*") + .to_owned(); tracing::debug!( "url rewrites glob pattern: {}", &rewrites_entry.source @@ -384,8 +388,12 @@ impl Settings { })? .compile_matcher(); - let pattern = - source.glob().regex().trim_start_matches("(?-u)").to_owned(); + let pattern = source + .glob() + .regex() + .trim_start_matches("(?-u)") + .replace("?:.*", ".*") + .to_owned(); tracing::debug!( "url redirects glob pattern: {}", &redirects_entry.source diff --git a/tests/toml/config.toml b/tests/toml/config.toml index d7a6821..3d3b3ff 100644 --- a/tests/toml/config.toml +++ b/tests/toml/config.toml @@ -127,6 +127,10 @@ destination = "/assets/$1.$2" source = "/abc/**/*.{svg,jxl}" destination = "/assets/favicon.ico" +[[advanced.rewrites]] +source = "/files/{*}" +destination = "/$1" + ### Name-based virtual hosting [[advanced.virtual-hosts]] -- libgit2 1.7.2