From 3cf13dc964d887b78cee90ad80c7aab5ce27d1d7 Mon Sep 17 00:00:00 2001 From: Jose Quintana <1700322+joseluisq@users.noreply.github.com> Date: Wed, 19 Jul 2023 17:25:09 +0200 Subject: [PATCH] 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. --- 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" -- libgit2 1.7.2