govspeak 3.5.0 → 3.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56a1d2187e10b165f7f6872389a4bf16e48c1ba9
4
- data.tar.gz: 04d622ee297eb5cbdd0284c42ecd2f8b0f8ef543
3
+ metadata.gz: 54b9c75ce59284172221f263176a47cc93035180
4
+ data.tar.gz: 9a6f7c98b35bc753ecc21e0e8aa25234867d2f19
5
5
  SHA512:
6
- metadata.gz: 63b8fb72f6f042920bca9e5b867101e2e03e1c46aac5ab32ce779fee79042ecf957f3c8311164308264ce8c36830bef951211275b37516b73318b88b8e13cff0
7
- data.tar.gz: f6fd90f8a72f143aa865f3535463e0e9a7e1f8049ac92ebf6c2c6a2a5780800101ce97fb0713b1046428e17a301d7cab61133bc6fb2f56cc47aed400b216aa6a
6
+ metadata.gz: 17fac603e4006e23750e4c129b69650d1ec106a71d0b1568a542fa4f1f65e474edd60c56d39de6297481281c1d1e45a51fbda84c41443915a63e9a9edb59006a
7
+ data.tar.gz: e29081388c7bf5207a68bd41a7dc1c1fdf0c3d7e3d040d88ee6ce102e9d19e91931f30144d3dc4299f8f0feb3f69c4481f06e3564a3d76767cb7cbf9641f04c5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.5.1
2
+
3
+ * Continue to support non-strict URIs in links on Ruby 2.2.x. See [https://github.com/alphagov/govspeak/issues/57](https://github.com/alphagov/govspeak/issues/57)
4
+
1
5
  ## 3.5.0
2
6
 
3
7
  * Add `{stat-headline}*10m* big numbers{/stat-headline}` markdown for HTML publications
@@ -1,3 +1,4 @@
1
+ require 'addressable/uri'
1
2
  require 'sanitize'
2
3
  require 'with_deep_merge'
3
4
 
@@ -13,7 +14,7 @@ class Govspeak::HtmlSanitizer
13
14
  return unless sanitize_context[:node_name] == "img"
14
15
 
15
16
  node = sanitize_context[:node]
16
- image_uri = URI.parse(node['src'])
17
+ image_uri = Addressable::URI.parse(node['src'])
17
18
  unless image_uri.relative? || @allowed_image_hosts.include?(image_uri.host)
18
19
  node.unlink # the node isn't sanitary. Remove it from the document.
19
20
  end
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "3.5.0"
2
+ VERSION = "3.5.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- require "uri"
1
+ require "addressable/uri"
2
2
  require "kramdown/options"
3
3
 
4
4
  module Kramdown
@@ -29,11 +29,11 @@ EOF
29
29
  def add_link(el, href, title, alt_text = nil)
30
30
  if el.type == :a
31
31
  begin
32
- host = URI.parse(href).host
32
+ host = Addressable::URI.parse(href).host
33
33
  unless host.nil? || (@document_domains.compact.include?(host))
34
34
  el.attr['rel'] = 'external'
35
35
  end
36
- rescue URI::InvalidURIError, URI::InvalidComponentError
36
+ rescue Addressable::URI::InvalidURIError
37
37
  # it's safe to ignore these very *specific* exceptions
38
38
  end
39
39
  end
@@ -257,14 +257,29 @@ Teston
257
257
  assert html.include?("¥")
258
258
  end
259
259
 
260
- test "should be assume link with invalid uri is internal" do
260
+ test "should assume a link with an invalid uri is internal" do
261
261
  html = Govspeak::Document.new("[link](:invalid-uri)").to_html
262
262
  refute html.include?('rel="external"')
263
263
  end
264
264
 
265
- test "should be assume link with invalid uri component is internal" do
266
- html = Govspeak::Document.new("[link](mailto://www.example.com)").to_html
265
+ test "should treat a mailto as internal" do
266
+ html = Govspeak::Document.new("[link](mailto:a@b.com)").to_html
267
267
  refute html.include?('rel="external"')
268
+ assert_equal %Q{<p><a href="mailto:a@b.com">link</a></p>\n}, deobfuscate_mailto(html)
269
+ end
270
+
271
+ test "permits mailto:// URI" do
272
+ html = Govspeak::Document.new("[link](mailto://a@b.com)").to_html
273
+ assert_equal %Q{<p><a rel="external" href="mailto://a@b.com">link</a></p>\n}, deobfuscate_mailto(html)
274
+ end
275
+
276
+ test "permits dud mailto: URI" do
277
+ html = Govspeak::Document.new("[link](mailto:)").to_html
278
+ assert_equal %Q{<p><a href="mailto:">link</a></p>\n}, deobfuscate_mailto(html)
279
+ end
280
+
281
+ test "permits trailing whitespace in an URI" do
282
+ Govspeak::Document.new("[link](http://example.com/%20)").to_html
268
283
  end
269
284
 
270
285
  # Regression test - the surrounded_by helper doesn't require the closing x
@@ -63,6 +63,14 @@ module GovspeakTestHelper
63
63
  asserter.instance_eval(&block)
64
64
  end
65
65
 
66
+ def deobfuscate_mailto(html)
67
+ # Kramdown obfuscates mailto addresses as an anti-spam measure. It
68
+ # obfuscates by encoding them as HTML entities.
69
+ # https://github.com/gettalong/kramdown/blob/7a7bd675b9d2593ad40c26fc4c77bf8407b70b42/lib/kramdown/converter/html.rb#L237-L246
70
+ coder = HTMLEntities.new
71
+ coder.decode(html)
72
+ end
73
+
66
74
  module ClassMethods
67
75
  def test_given_govspeak(govspeak, images=[], options = {}, &block)
68
76
  test "Given #{govspeak}" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Griffiths
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-09 00:00:00.000000000 Z
12
+ date: 2015-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.5'
70
+ - !ruby/object:Gem::Dependency
71
+ name: addressable
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 2.3.8
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 2.3.8
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rake
72
86
  requirement: !ruby/object:Gem::Requirement