summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-14 22:22:55 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-14 22:22:55 +0200
commit9996da20c88d45c34b8f1267b23b83ae1e1bbea3 (patch)
tree8c9b1b2296a02de17ff91a7ec535c0dc5b392f6d
parent39fa281fa05a8b3c1e56954c5db4dcabcc1b6d8e (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.
-rw-r--r--lib/rbot/core/utils/utils.rb11
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