RegexpError:regexp匹配器中的堆栈溢出:/ \ A(?:%[0-9a-fA-F] {2} | [^%])* \ z /

时间:2013-08-21 15:52:50

标签: ruby regex sinatra rack

我们有小型的Sinatra应用程序,运行在REE 1.8.7p-358上

NewRelic报告了一些类似的问题:

RegexpError: Stack overflow in regexp matcher: /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/

.../gems/rack-1.4.1/lib/rack/backports/uri/common_18.rb:  67:in `decode_www_form_component'
.../gems/rack-1.4.1/lib/rack/utils.rb:  43:in `unescape'
.../gems/rack-1.4.1/lib/rack/utils.rb:  88:in `parse_nested_query'
.../gems/rack-1.4.1/lib/rack/utils.rb:  88:in `map'
.../gems/rack-1.4.1/lib/rack/utils.rb:  88:in `parse_nested_query'
.../gems/rack-1.4.1/lib/rack/utils.rb:  87:in `each'
.../gems/rack-1.4.1/lib/rack/utils.rb:  87:in `parse_nested_query'
.../gems/rack-1.4.1/lib/rack/request.rb: 334:in `parse_query'
.../gems/rack-1.4.1/lib/rack/request.rb: 209:in `POST'
.../gems/rack-1.4.1/lib/rack/request.rb: 221:in `params'
.../gems/sinatra-1.2.6/lib/sinatra/base.rb: 638:in `call!'
.../gems/sinatra-1.2.6/lib/sinatra/base.rb: 629:in `call'

从Rack来源我看到它使用/\A(?:%[0-9a-fA-F]{2}|[^%])*\z/来检测无效的%-encoding:

raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str

我想尝试在本地重现错误。 我的问题是:在尝试将其与/\A(?:%[0-9a-fA-F]{2}|[^%])*\z/

进行比较时,应该在regexp matcher中导致堆栈溢出的字符串是什么

1 个答案:

答案 0 :(得分:-2)

如果有多个%,则表达式/\A(?:%[0-9a-fA-F]{2}|[^%])*\z/被抛弃。我一直在Rubular

进行测试