Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't mess with absolute links.

  • Loading branch information...
commit 38c454a3507b3d1e27e37a22c69711941f3680c7 1 parent 405b42b
@lazyatom authored
Showing with 17 additions and 4 deletions.
  1. +9 −4 lib/vanilla/atom_feed.rb
  2. +8 −0 test/core/atom_feed_test.rb
View
13 lib/vanilla/atom_feed.rb
@@ -63,10 +63,15 @@ def atom_time(time)
end
def externalise_links(content)
- content.gsub(/href=(["'])\//, "href=\\1http://#{domain}/").
- gsub(/href=(["'])/, "href=\\1http://#{domain}/").
- gsub(/src=(["'])\//, "src=\\1http://#{domain}/").
- gsub(/src=(["'])/, "src=\\1http://#{domain}/")
+ content.gsub(/(href|src)=(["'])(\/?.*)\2/) do
+ type, quote, link = $1, $2, $3
+ if link =~ /^http/
+ "#{type}=#{quote}#{link}#{quote}"
+ else
+ absolute_link = "http://#{domain}" + (link =~ /^\// ? "" : "/") + link
+ "#{type}=#{quote}#{absolute_link}#{quote}"
+ end
+ end
end
end
end
View
8 test/core/atom_feed_test.rb
@@ -75,6 +75,14 @@
assert feed.entries.first.content =~ %r{http://yourdomain\.example\.com/x.jpg},
"single-quoted links external should work (got: #{feed.entries.first.content})"
end
+
+ should "not alter urls that are already absolute" do
+ stub_app_soup({:name => "x", :content => %|<img src='http://x.com/' />|})
+
+ feed = get_feed
+ assert feed.entries.first.content =~ %r{src='http://x\.com/'},
+ "should not alter absolute links (got: #{feed.entries.first.content})"
+ end
end
should "allow inclusion of only specific snips" do
Please sign in to comment.
Something went wrong with that request. Please try again.