Fix the regex pattern to reduce backtracking

This should fix #1832.
This commit is contained in:
Akinori MUSHA 2016-12-20 10:26:39 +09:00
parent cb2b906067
commit 2a524abff5

View file

@ -206,7 +206,7 @@ module Agents
else
# Encoding is already known, so do not let the parser detect
# it from the XML declaration in the content.
body.sub!(/(\A\u{FEFF}?\s*<\?xml(?:\s+\w+\s*=\s*(['"]).*?\2)*)\s+encoding\s*=\s*(['"]).*?\3/, '\\1')
body.sub!(/(?<noenc>\A\u{FEFF}?\s*<\?xml(?:\s+\w+(?<av>\s*=\s*(?:'[^']*'|"[^"]*")))*?)\s+encoding\g<av>/, '\\k<noenc>')
end
body
end