Skip to content

Commit 1635706

Browse files
committed
Match all github.com subdomains
1 parent a4db302 commit 1635706

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/html/pipeline/camo_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def call
3131
end
3232

3333
next if uri.hostname.nil?
34-
next if uri.hostname.match(/^(\w+\.)?github(app)?\.com$/)
34+
next if uri.hostname.match(/(^|\.)github(app)?\.com$/)
3535

3636
element['src'] = asset_proxy_url(uri.to_s)
3737
end

test/html/pipeline/camo_filter_test.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,30 @@ def test_doesnt_rewrite_dotcom_subdomain_image_urls
3030
CamoFilter.call(orig, @options).to_s
3131
end
3232

33+
def test_doesnt_rewrite_dotcom_subsubdomain_image_urls
34+
orig = %(<p><img src="https://f.assets.github.com/img.png"></p>)
35+
assert_equal "<p><img src=\"https://f.assets.github.com/img.png\"></p>",
36+
CamoFilter.call(orig, @options).to_s
37+
end
38+
39+
def test_camouflaging_github_prefixed_image_urls
40+
orig = %(<p><img src="https://notgithub.com/img.png"></p>)
41+
assert_includes 'img src="' + @asset_proxy_url,
42+
CamoFilter.call(orig, @options).to_s
43+
end
44+
3345
def test_doesnt_rewrite_dotcom_app_image_urls
3446
orig = %(<p><img src="https://githubapp.com/img.png"></p>)
3547
assert_equal "<p><img src=\"https://githubapp.com/img.png\"></p>",
3648
CamoFilter.call(orig, @options).to_s
3749
end
3850

51+
def test_rewrite_dotcom_app_image_urls
52+
orig = %(<p><img src="https://githubapp.com/img.png"></p>)
53+
assert_equal "<p><img src=\"https://githubapp.com/img.png\"></p>",
54+
CamoFilter.call(orig, @options).to_s
55+
end
56+
3957
def test_doesnt_rewrite_absolute_image_urls
4058
orig = %(<p><img src="/img.png"></p>)
4159
assert_equal "<p><img src=\"/img.png\"></p>",
@@ -48,7 +66,6 @@ def test_doesnt_rewrite_relative_image_urls
4866
CamoFilter.call(orig, @options).to_s
4967
end
5068

51-
5269
def test_camouflaging_https_image_urls
5370
orig = %(<p><img src="https://foo.com/img.png"></p>)
5471
assert_includes 'img src="' + @asset_proxy_url,

0 commit comments

Comments
 (0)