From 9996da20c88d45c34b8f1267b23b83ae1e1bbea3 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 14 Apr 2008 22:22:55 +0200 Subject: 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. --- lib/rbot/core/utils/utils.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') 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 = /.*?]*name=["']?#{frag}["']?.*?>/im - txt.sub!(fragreg,'') + fragreg = /]*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 -- cgit v1.2.3