html-pipeline 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/html/pipeline/camo_filter.rb +5 -4
- data/lib/html/pipeline/version.rb +1 -1
- data/test/html/pipeline/camo_filter_test.rb +8 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18ebd2d23ad0e2b826d0f799544324f75efad1c4
|
4
|
+
data.tar.gz: c052603aa7e7dd3af1b9b75f55a52ad4be278fbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5177792a0de9b78ccdfeb86c2b335ed25dcc83a2e10db7c8fa34236ec61e6746fb358c593fc156739c338144332e7e6f193300a6399485e1ea5210af3424ff2
|
7
|
+
data.tar.gz: 905067a669f37813c52858536ebda8af639ba6b3b1929b361acd4f9460d06881f922db57f40033f2eb15b7eb061a31b365d497e0b19b6863ebbf42401bc7dc35
|
data/CHANGELOG.md
CHANGED
@@ -25,10 +25,11 @@ module HTML
|
|
25
25
|
return unless asset_proxy_enabled?
|
26
26
|
|
27
27
|
doc.search("img").each do |element|
|
28
|
-
|
28
|
+
original_src = element['src']
|
29
|
+
next unless original_src
|
29
30
|
|
30
31
|
begin
|
31
|
-
uri = URI.parse(
|
32
|
+
uri = URI.parse(original_src)
|
32
33
|
rescue Exception
|
33
34
|
next
|
34
35
|
end
|
@@ -36,8 +37,8 @@ module HTML
|
|
36
37
|
next if uri.host.nil?
|
37
38
|
next if asset_host_whitelisted?(uri.host)
|
38
39
|
|
39
|
-
element['src'] = asset_proxy_url(
|
40
|
-
element['data-canonical-src'] =
|
40
|
+
element['src'] = asset_proxy_url(original_src)
|
41
|
+
element['data-canonical-src'] = original_src
|
41
42
|
end
|
42
43
|
doc
|
43
44
|
end
|
@@ -15,51 +15,44 @@ class HTML::Pipeline::CamoFilterTest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
def test_camouflaging_http_image_urls
|
17
17
|
orig = %(<p><img src="http://twitter.com/img.png"></p>)
|
18
|
-
|
19
|
-
CamoFilter.call(orig, @options).to_s
|
20
|
-
assert_includes 'data-canonical-src="http://twitter.com/img.png"',
|
18
|
+
assert_equal %(<p><img src="https//assets.example.org/a5ad43494e343b20d745586282be61ff530e6fa0/687474703a2f2f747769747465722e636f6d2f696d672e706e67" data-canonical-src="http://twitter.com/img.png"></p>),
|
21
19
|
CamoFilter.call(orig, @options).to_s
|
22
20
|
end
|
23
21
|
|
24
22
|
def test_doesnt_rewrite_dotcom_image_urls
|
25
23
|
orig = %(<p><img src="https://github.com/img.png"></p>)
|
26
|
-
assert_equal
|
27
|
-
CamoFilter.call(orig, @options).to_s
|
24
|
+
assert_equal orig, CamoFilter.call(orig, @options).to_s
|
28
25
|
end
|
29
26
|
|
30
27
|
def test_doesnt_rewrite_dotcom_subdomain_image_urls
|
31
28
|
orig = %(<p><img src="https://raw.github.com/img.png"></p>)
|
32
|
-
assert_equal
|
33
|
-
CamoFilter.call(orig, @options).to_s
|
29
|
+
assert_equal orig, CamoFilter.call(orig, @options).to_s
|
34
30
|
end
|
35
31
|
|
36
32
|
def test_doesnt_rewrite_dotcom_subsubdomain_image_urls
|
37
33
|
orig = %(<p><img src="https://f.assets.github.com/img.png"></p>)
|
38
|
-
assert_equal
|
39
|
-
CamoFilter.call(orig, @options).to_s
|
34
|
+
assert_equal orig, CamoFilter.call(orig, @options).to_s
|
40
35
|
end
|
41
36
|
|
42
37
|
def test_camouflaging_github_prefixed_image_urls
|
43
38
|
orig = %(<p><img src="https://notgithub.com/img.png"></p>)
|
44
|
-
|
39
|
+
assert_equal %(<p><img src="https//assets.example.org/5d4a96c69713f850520538e04cb9661035cfb534/68747470733a2f2f6e6f746769746875622e636f6d2f696d672e706e67" data-canonical-src="https://notgithub.com/img.png"></p>),
|
45
40
|
CamoFilter.call(orig, @options).to_s
|
46
41
|
end
|
47
42
|
|
48
43
|
def test_doesnt_rewrite_absolute_image_urls
|
49
44
|
orig = %(<p><img src="/img.png"></p>)
|
50
|
-
assert_equal
|
51
|
-
CamoFilter.call(orig, @options).to_s
|
45
|
+
assert_equal orig, CamoFilter.call(orig, @options).to_s
|
52
46
|
end
|
53
47
|
|
54
48
|
def test_doesnt_rewrite_relative_image_urls
|
55
49
|
orig = %(<p><img src="img.png"></p>)
|
56
|
-
assert_equal
|
57
|
-
CamoFilter.call(orig, @options).to_s
|
50
|
+
assert_equal orig, CamoFilter.call(orig, @options).to_s
|
58
51
|
end
|
59
52
|
|
60
53
|
def test_camouflaging_https_image_urls
|
61
54
|
orig = %(<p><img src="https://foo.com/img.png"></p>)
|
62
|
-
|
55
|
+
assert_equal %(<p><img src="https//assets.example.org/3c5c6dc74fd6592d2596209dfcb8b7e5461383c8/68747470733a2f2f666f6f2e636f6d2f696d672e706e67" data-canonical-src="https://foo.com/img.png"></p>),
|
63
56
|
CamoFilter.call(orig, @options).to_s
|
64
57
|
end
|
65
58
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|