Skip to content

Commit f044011

Browse files
authored
Merge pull request #9 from rkaiser0324/fix/rewrite-rule-e-flag
Clarify that RewriteRule E flag is unsupported, and fix some parsing cases
2 parents 7e8370d + 1cb7a30 commit f044011

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ mod_negotiation | `ForceLanguagePriority` | No |
231231
mod_negotiation | `LanguagePriority` | No |
232232
mod_reflector | `*` | Never | Security reasons
233233
mod_rewrite | `RewriteBase` | Yes |
234-
mod_rewrite | `RewriteCond` | Yes |
234+
mod_rewrite | `RewriteCond` | Partial | Environment (E=) flag is unsupported
235235
mod_rewrite | `RewriteEngine` | Yes |
236236
mod_rewrite | `RewriteOptions` | No |
237237
mod_rewrite | `RewriteRule` | Yes |

htaccess.lua

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,13 @@ local replace_server_vars = function(str, track_used_headers)
748748
if first_five == 'http_' then -- %{HTTC_*}, e.g. %{HTTC_HOST}
749749
replace = ngx.var[svar] or ''
750750
if track_used_headers then
751-
table.insert(used_headers, svar:sub(6):gsub('_', '-'):lower())
751+
table.insert(used_headers, (svar:sub(6):gsub('_', '-'):lower()))
752752
end
753753
elseif first_five == 'http:' then -- %{HTTP:*}, e.g. %{HTTP:Content-Type}
754754
svar = svar:sub(6):gsub('-','_'):lower()
755755
replace = ngx.var['http_'..svar] or ''
756756
if track_used_headers then
757-
table.insert(used_headers, svar:gsub('_', '-'))
757+
table.insert(used_headers, (svar:gsub('_', '-')))
758758
end
759759
elseif first_five == 'time_' then -- %{TIME_*}, e.g. %{TIME_YEAR}
760760
svar = svar:sub(6)
@@ -813,7 +813,12 @@ local current_dir
813813
local stat_instructions_used = {}
814814
local stat_blocks_used = {}
815815
for statement in htaccess:gmatch('[^\r\n]+') do
816-
if statement:sub(1,1) == '<' then
816+
-- Trim leading whitespace
817+
statement = statement:gsub("^%s*", "");
818+
819+
if statement:sub(1,1) == '#' then
820+
-- Comment, so ignore it
821+
elseif statement:sub(1,1) == '<' then
817822
-- handle blocks
818823
if statement:sub(2,2) ~= '/' then
819824
-- opening tag <...>
@@ -987,6 +992,7 @@ for statement in htaccess:gmatch('[^\r\n]+') do
987992
pop_ctx()
988993
end
989994
end
995+
990996
else
991997
local instruction = statement:match('^[^%s]+')
992998
if instruction then
@@ -1207,11 +1213,9 @@ if get_cdir('rewrite') and #parsed_rewriterules > 0 then
12071213
elseif flag == 'qsa' or flag == 'qsappend' then -- [QSA]
12081214
local qs = relative_uri:match('%?.*')
12091215
if qs then
1210-
local new_qs = dst:match('%?.*')
1216+
local new_qs = dst:match('%?.*')
12111217
if new_qs then
12121218
dst = dst:gsub('%?.*', '', 1)..qs..'&'..new_qs:sub(2)
1213-
else
1214-
dst = dst..new_qs
12151219
end
12161220
end
12171221
elseif flag == 'qsd' or flag == 'qsdiscard' then -- [QSD]
@@ -1222,6 +1226,10 @@ if get_cdir('rewrite') and #parsed_rewriterules > 0 then
12221226
else
12231227
fail('Invalid flag value: ['..rawflag..'], expecting a number')
12241228
end
1229+
elseif flag == 'e' then -- [E=]
1230+
-- Trying to set or unset an environment variable
1231+
-- https://httpd.apache.org/docs/2.4/rewrite/flags.html
1232+
fail('RewriteRule flag E is unsupported')
12251233
else
12261234
fail('Unsupported RewriteRule flag: '..flag)
12271235
end

0 commit comments

Comments
 (0)