index : static-web-server.git

ascending towards madness

author Jose Quintana <1700322+joseluisq@users.noreply.github.com> 2023-09-19 4:41:24.0 +00:00:00
committer GitHub <noreply@github.com> 2023-09-19 4:41:24.0 +00:00:00
commit
2e3e49f880bac4fcf66c7a9da73947250847fef7 [patch]
tree
94148fc78ddf006fea3240dad8868861379adcb5
parent
85e85f3a47f03bfae92b9274ca24899090c8cc3d
download
2e3e49f880bac4fcf66c7a9da73947250847fef7.tar.gz

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"
```

Diff

 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]]