index : static-web-server.git

ascending towards madness

author Jose Quintana <1700322+joseluisq@users.noreply.github.com> 2023-07-19 15:25:09.0 +00:00:00
committer GitHub <noreply@github.com> 2023-07-19 15:25:09.0 +00:00:00
commit
3cf13dc964d887b78cee90ad80c7aab5ce27d1d7 [patch]
tree
20153cc88b29da1865073968b3cb1390d332b5e1
parent
0d8762202ab04a7d65f940cc79a7943ce9b62688
download
3cf13dc964d887b78cee90ad80c7aab5ce27d1d7.tar.gz

fix: url rewrites don't work without replacements (#244)

this fixes a regression #243 introduced by v2.20.0 when using url rewrites with out replacements.

Diff

 src/settings/mod.rs    | 14 ++++----------
 tests/toml/config.toml | 12 +++++++++++-
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/settings/mod.rs b/src/settings/mod.rs
index 9b165f2..71ab5ea 100644
--- a/src/settings/mod.rs
+++ b/src/settings/mod.rs
@@ -333,11 +333,8 @@ impl Settings {
                                    })?
                                    .compile_matcher();

                                // NOTE: we don’t need Unicode-aware word boundary assertions,
                                // therefore we use (?-u:\b) instead of (?-u)
                                // so the former uses an ASCII-only definition of a word character.
                                // https://docs.rs/regex/latest/regex/#unicode-can-impact-memory-usage-and-search-speed
                                let pattern = source.glob().regex().replace("(?-u)^", "(?-u:\\b)");
                                let pattern =
                                    source.glob().regex().trim_start_matches("(?-u)").to_owned();
                                tracing::debug!(
                                    "url rewrites glob pattern: {}",
                                    &rewrites_entry.source
@@ -378,11 +375,8 @@ impl Settings {
                                    })?
                                    .compile_matcher();

                                // NOTE: we don’t need Unicode-aware word boundary assertions,
                                // therefore we use (?-u:\b) instead of (?-u)
                                // so the former uses an ASCII-only definition of a word character.
                                // https://docs.rs/regex/latest/regex/#unicode-can-impact-memory-usage-and-search-speed
                                let pattern = source.glob().regex().replace("(?-u)^", "(?-u:\\b)");
                                let pattern =
                                    source.glob().regex().trim_start_matches("(?-u)").to_owned();
                                tracing::debug!(
                                    "url rewrites glob pattern: {}",
                                    &redirects_entry.source
diff --git a/tests/toml/config.toml b/tests/toml/config.toml
index fe9849b..0796426 100644
--- a/tests/toml/config.toml
+++ b/tests/toml/config.toml
@@ -109,10 +109,20 @@ kind = 302
### URL Rewrites

[[advanced.rewrites]]
source = "/image.ico"
destination = "/assets/favicon.ico"
# redirect = 301

[[advanced.rewrites]]
source = "/{picture}.{ico,webp}"
destination = "/assets/$1.$2"
# redirect = 301

[[advanced.rewrites]]
source = "**/{*}.{png,gif}"
destination = "/assets/$1.$2"
# redirect = 301

[[advanced.rewrites]]
source = "**/*.{jpg,jpeg}"
source = "/abc/**/*.{svg,jxl}"
destination = "/assets/favicon.ico"