Skip to content

Conversation

@yezhiyi9670
Copy link

@yezhiyi9670 yezhiyi9670 commented Dec 5, 2025

When using unfiltered string as replacement, it is important to escape the % characters to prevent "invalid capture index" errors. This is properly done in:

But not here:

Consider this rewrite rule set, which is modified from Wordpress default:

<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php?%{QUERY_STRING} [L]
</IfModule>

If the last rule is triggered with query string that contains something like %2C, the script will crash. This commit fixes it by also doing replace:gsub('%%', '%%%%')..''.


The second commit fixed #37. I accidentally committed it to the same branch.

Ensure replacement does not use capture indexes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<Files> section cause crash when accessing directories

1 participant