diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-04-14 22:22:55 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-04-14 22:22:55 +0200 |
commit | 9996da20c88d45c34b8f1267b23b83ae1e1bbea3 (patch) | |
tree | 8c9b1b2296a02de17ff91a7ec535c0dc5b392f6d /lib/rbot | |
parent | 39fa281fa05a8b3c1e56954c5db4dcabcc1b6d8e (diff) |
utils: don't hang when getting first par with nonexistant uri-fragment
When an URL is passed which has a uri-fragment referring to a
nonexisting named ref, the bot should not hang with 100% CPU usage
while trying to match a horribly designed regular expression.
Fix by using a much simpler regexp and post-match.
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/utils.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb index 7b1ff7f1..ce5cdea4 100644 --- a/lib/rbot/core/utils/utils.rb +++ b/lib/rbot/core/utils/utils.rb @@ -618,11 +618,18 @@ module ::Irc # uri_fragment:: the URI fragment of the original request # def Utils.get_string_html_info(text, opts={}) + debug "getting string html info" txt = text.dup title = txt.ircify_html_title + debug opts if frag = opts[:uri_fragment] and not frag.empty? - fragreg = /.*?<a\s+[^>]*name=["']?#{frag}["']?.*?>/im - txt.sub!(fragreg,'') + fragreg = /<a\s+[^>]*name=["']?#{frag}["']?[^>]*>/im + debug fragreg + debug txt + if txt.match(fragreg) + # grab the post-match + txt = $' + end end c_opts = opts.dup c_opts[:strip] ||= title |