Repository: static-web-server/static-web-server (language: rust)

Issue:
URL Rewrites not capturing glob groups correctly
**Describe the bug**
URL rewrites fails to capture globs.

**To Reproduce**
1) from a directory with files in it (here let's say `~/root` with `~/root/asset`)
2) Add the following in a config file (`~/root/conf.toml`) :
```toml
[general]
host = "::"
port = 50000
root = "."
cors-allow-origins = "*"

[[advanced.rewrites]]
source = "/root2/{**}"
destination = "/$1"
```
4) Run the server from `~/root`: `static-web-server -w conf.toml --log-level "debug"`
5) Open `http://localhost:50000/root2/asset`

**Expected behavior**
The glob `asset` is matched and the server finds it

**Logs/Screenshots**
(timestamps removed for readability )
(my `asset` here is a file called `addon.json`)
```
  INFO static_web_server::handler: incoming request: method=GET uri=/root2/addon.json
 DEBUG static_web_server::handler: cors state: NotCors
 DEBUG static_web_server::handler: url rewrites glob pattern: ["$0"]
 DEBUG static_web_server::handler: url rewrites regex equivalent: ^/root2/(?:.*.*)$
 DEBUG static_web_server::handler: url rewrites glob pattern captures: ["/root2/addon.json"]
 DEBUG static_web_server::handler: url rewrites glob pattern destination: "/$1"
 DEBUG static_web_server::handler: url rewrites glob pattern destination replaced: "/$1"
 DEBUG static_web_server::static_files: file not found: "./$1" Os { code: 2, kind: NotFound, message: "No such file or directory" }
 DEBUG static_web_server::static_files: file: appending .html to the path
 DEBUG static_web_server::static_files: file not found: "./$1.html" Os { code: 2, kind: NotFound, message: "No such file or directory" }
  WARN static_web_server::error_page: method=GET uri=/root2/addon.json status=404 error="Not Found"
```

**Environment and Specs**
 - static-web-server: v2.22.0
 - OS: Fedora 38
 - Docker: (not used)
 - Client: Firefox 117.0

**Additional context**
When requesting a uri completely different (like `root3/asset`), the logs don't even include any part mentioning rewrites and failed matches, so I'm assuming the server does recognize there is a match on the uri, but it fails to capture the glob as it is meant to.


Discussion / hints:
I was able to reproduce it too.
Basically, for the conversion of `/root2/{**}` glob to its equivalent `regex`, the code is returning `^/root2/(?:.*)$` (non-capturing group) instead of `^/root2/(.*)$` (numbered index capture group). I do not why, but it is easy to fix.

A patch release should come in the coming hours.

Fix patch:
diff --git a/src/settings/mod.rs b/src/settings/mod.rs
index 0429bee8..39023b2d 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


Test patch:
diff --git a/tests/toml/config.toml b/tests/toml/config.toml
index d7a68212..3d3b3ffc 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]]