Skip to content

Commit

Permalink
handle null value
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhimin Zhan committed Jul 30, 2009
1 parent dcbfe3d commit 71f5423
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/rwebunit/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ def absolutize_page_hpricot(content, base_url, parent_url)
require 'hpricot'
doc = Hpricot(content)
base_url.slice!(-1) if ends_with?(base_url, "/")
(doc/'link').each { |e| e['href'] = absolutify_url(e['href'], base_url, parent_url) }
(doc/'script').each { |e| e['src'] = absolutify_url(e['src'], base_url, parent_url) }
(doc/'img').each { |e| e['src'] = absolutify_url(e['src'], base_url, parent_url) }
(doc/'link').each { |e| e['href'] = absolutify_url(e['href'], base_url, parent_url) || ""}
(doc/'img').each { |e| e['src'] = absolutify_url(e['src'], base_url, parent_url) || ""}
(doc/'script').each { |e| e['src'] = absolutify_url(e['src'], base_url, parent_url) || ""}
return doc.to_html
rescue => e
absolutize_page(content, base_url, parent_url)
Expand All @@ -420,12 +420,12 @@ def absolutize_page_hpricot(content, base_url, parent_url)
# to
# <script type="text/javascript" src="http://itest2.com/javascripts/prototype.js"></script>
def absolutify_url(src, base_url, parent_url)
if src.nil? || src.empty? || src == "//:" || src =~ /\s*http:\/\//
if src.nil? || src.empty? || src == "//:" || src =~ /\s*http:\/\//i
return src
end

return "#{base_url}#{src}"if src =~ /^\s*\//
return "#{parent_url}#{src}"if parent_url
return "#{base_url}#{src}" if src =~ /^\s*\//
return "#{parent_url}#{src}" if parent_url
return src
end

Expand Down

0 comments on commit 71f5423

Please sign in to comment.