diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-03-09 18:03:34 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-03-09 18:03:57 +0200 |
commit | 974d3e061250bd82e72af3cc3c0638446f12bb88 (patch) | |
tree | b501a9f685be05917109b42dd24fb86be92fdd1f | |
parent | 129d3c8675dbb67666fd6018716b11e7706cadb8 (diff) | |
download | haproxy-bulkredirect-974d3e061250bd82e72af3cc3c0638446f12bb88.tar.gz haproxy-bulkredirect-974d3e061250bd82e72af3cc3c0638446f12bb88.tar.bz2 |
Don't modify the table while iterating over it (complements 5976177e64).
-rw-r--r-- | bulkredirect.lua | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/bulkredirect.lua b/bulkredirect.lua index d047b65..f995a3c 100644 --- a/bulkredirect.lua +++ b/bulkredirect.lua @@ -301,6 +301,28 @@ local function www_complement (name) return s end +local function populate_www_complements (rt, dup) + local crt = {} + + for d,t in pairs(rt) do + local compl = www_complement(d) + if rt[compl] then + for k,v in pairs(t) do + -- FIXME: Error message if rt[compl][k] exists + crt[compl][k] = clone(v) + end + elseif dup then + crt[compl] = clone(t) + else + crt[compl] = d + end + end + + for d,t in pairs(crt) do + rt[d] = t + end +end + local function load_redirect_file (f, filename) local domain local ln = 1 @@ -364,17 +386,7 @@ local function load_redirect_file (f, filename) if www == optab['www'] then return elseif www then - for d,t in pairs(rt) do - local compl = www_complement(d) - if rt[compl] then - for k,v in pairs(t) do - -- FIXME: Error message if rt[compl][k] exists - rt[compl][k] = clone(v) - end - else - rt[compl] = clone(t) - end - end + populate_www_complements (rt, true) www = nil end end @@ -404,21 +416,7 @@ local function load_redirect_file (f, filename) end if www then - crt = {} - for d,t in pairs(rt) do - local compl = www_complement(d) - if rt[compl] then - for k,v in pairs(t) do - -- FIXME: Error message if rt[compl][k] exists - crt[compl][k] = clone(v) - end - else - crt[compl] = d - end - end - for d,t in pairs(crt) do - rt[d] = t - end + populate_www_complements (rt, false) www = nil end |