Skip to content

Commit c2dd2f7

Browse files
committed
Skip github.com and githubapp.com images
1 parent edbcb81 commit c2dd2f7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/html/pipeline/camo_filter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ class CamoFilter < Filter
2121
def call
2222
doc.search("img").each do |element|
2323
next if element['src'].nil?
24+
next if context[:disable_asset_proxy]
25+
2426
src = element['src'].strip
25-
src = src.sub(%r!^http://github.com!, 'https://github.com')
27+
next if src.match(%r!^https://(\w+\.)?github(app)?.com!)
2628

27-
next if context[:disable_asset_proxy]
2829
element['src'] = asset_proxy_url(src)
2930
end
3031
doc

test/html/pipeline/camo_filter_test.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@ def test_camouflaging_http_image_urls
1818
CamoFilter.call(orig, @options).to_s
1919
end
2020

21-
def test_rewrites_dotcom_image_urls
22-
orig = %(<p><img src="http://github.com/img.png"></p>)
21+
def test_doesnt_rewrite_dotcom_image_urls
22+
orig = %(<p><img src="https://github.com/img.png"></p>)
2323
assert_equal "<p><img src=\"https://github.com/img.png\"></p>",
2424
CamoFilter.call(orig, @options).to_s
2525
end
2626

27+
def test_doesnt_rewrite_dotcom_subdomain_image_urls
28+
orig = %(<p><img src="https://raw.github.com/img.png"></p>)
29+
assert_equal "<p><img src=\"https://raw.github.com/img.png\"></p>",
30+
CamoFilter.call(orig, @options).to_s
31+
end
32+
33+
def test_doesnt_rewrite_dotcom_app_image_urls
34+
orig = %(<p><img src="https://githubapp.com/img.png"></p>)
35+
assert_equal "<p><img src=\"https://githubapp.com/img.png\"></p>",
36+
CamoFilter.call(orig, @options).to_s
37+
end
38+
2739
def test_camouflaging_https_image_urls
2840
orig = %(<p><img src="https://foo.com/img.png"></p>)
2941
assert_includes 'img src="' + @asset_proxy_url,

0 commit comments

Comments
 (0)