govspeak 6.7.7 → 6.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eeb616e6f8489b589e1ddda16e92727ec5c30a9ad76b88e89184aad8590276e3
4
- data.tar.gz: cc776bc6208ca7baafce665f4c92a549f2ee6c70fa96652e81e2ed8a32a45f5a
3
+ metadata.gz: 5613d3c42e9347e578dd2ed9d2164c08cc81cfc70f8ade79deb56fc77069056f
4
+ data.tar.gz: 1157c2a33c97ae726af931714252eaa460216f1254a47449c4db187fff197c1d
5
5
  SHA512:
6
- metadata.gz: cb08b6e651a21f26ae42efff15d74b80401b1dc26fd516b69b02394b9eeaa20825aa4e176ef789a35ae035bb5d8be13012fb42e35c88e1e487870c81c8c4d0af
7
- data.tar.gz: 1dc3a85af8fb5ecacb8c9a530739e8f3742fa9ea79bd3830c73c2c5d36b907d737aec74e028a4df197f11e1c0bd7d55eb25e3f5d0009a22a930cfb4e0b449f50
6
+ metadata.gz: aa8cca4a71fd2f9b029c545714ccf032ead1fe07389ce49571aa5f14093b95bd7ae05ddc2188bea959ea60ac59c042bc0b56729b8a197782291869e7e0cf947e
7
+ data.tar.gz: 12dcd4d62d0b6b16a651d001145f2aaa942991c972a00720d598464633f2eb8ead57d50dc0609ed1eb6a25a328399380dac55d97aa7101cdd52483b46b6c700c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 6.8.1
2
+
3
+ * Fix a bug which resulted in validation errors on 'Start Button' elements [#237](https://github.com/alphagov/govspeak/pull/237)
4
+
5
+ ## 6.8.0
6
+
7
+ * Drop support for Ruby 2.6 which reaches End of Life (EOL) on 31/03/2022
8
+ * Add support for Rails 7 by loosening the version constraint on `activeview` gem
9
+ * Fix deprecation notices caused by the bump in Ruby version
10
+
11
+ ## 6.7.8
12
+
13
+ * Fixes bug which reverts acronyms from being converted into abbr tags [#229](https://github.com/alphagov/govspeak/pull/229)
14
+
1
15
  ## 6.7.7
2
16
 
3
17
  * Fix broken HTML in CTA extension. [#226](https://github.com/alphagov/govspeak/pull/226)
data/README.md CHANGED
@@ -28,8 +28,7 @@ Once govspeak has been updated and version incremented then:
28
28
 
29
29
  Also, consider if:
30
30
  - [whitehall](https://github.com/alphagov/whitehall) needs updating (as custom govspeak changes are present)
31
- - [govuk-content-schema](https://github.com/alphagov/govuk-content-schemas) needs updating
32
- - [govpspeak-preview](https://github.com/alphagov/govspeak-preview) is worth updating
31
+ - [govpspeak-preview](https://github.com/alphagov/govspeak-preview) needs updating
33
32
 
34
33
  Any pages that use govspeak to generate Content will need to *republished* in order for the new changes to be reflected.
35
34
 
@@ -46,7 +46,17 @@ class Govspeak::HtmlSanitizer
46
46
  transformers << ImageSourceWhitelister.new(@allowed_image_hosts)
47
47
  end
48
48
 
49
- Sanitize.clean(@dirty_html, Sanitize::Config.merge(sanitize_config(allowed_elements: allowed_elements), transformers: transformers))
49
+ # It would be cleaner to move this `transformers` key into the `sanitize_config` method rather
50
+ # than having to use Sanitize::Config.merge() twice in succession. However, `sanitize_config`
51
+ # is a public method and it looks like other projects depend on it behaving the way it
52
+ # currently does – i.e. to return Sanitize config without any transformers.
53
+ # e.g. https://github.com/alphagov/hmrc-manuals-api/blob/4a83f78d0bb839520155623fd9b63b3b12a3b13a/app/validators/no_dangerous_html_in_text_fields_validator.rb#L44
54
+ config_with_transformers = Sanitize::Config.merge(
55
+ sanitize_config(allowed_elements: allowed_elements),
56
+ transformers: transformers,
57
+ )
58
+
59
+ Sanitize.clean(@dirty_html, config_with_transformers)
50
60
  end
51
61
 
52
62
  def sanitize_config(allowed_elements: [])
@@ -1,9 +1,9 @@
1
1
  class Govspeak::HtmlValidator
2
2
  attr_reader :govspeak_string
3
3
 
4
- def initialize(govspeak_string, sanitization_options = {})
4
+ def initialize(govspeak_string, options = {})
5
5
  @govspeak_string = govspeak_string.dup.force_encoding(Encoding::UTF_8)
6
- @sanitization_options = sanitization_options
6
+ @allowed_image_hosts = options[:allowed_image_hosts]
7
7
  end
8
8
 
9
9
  def invalid?
@@ -11,17 +11,23 @@ class Govspeak::HtmlValidator
11
11
  end
12
12
 
13
13
  def valid?
14
- dirty_html = govspeak_to_html
15
- clean_html = Govspeak::HtmlSanitizer.new(dirty_html, @sanitization_options).sanitize
14
+ dirty_html = govspeak_to_html(sanitize: false)
15
+ clean_html = govspeak_to_html(sanitize: true)
16
16
  normalise_html(dirty_html) == normalise_html(clean_html)
17
17
  end
18
18
 
19
+ private
20
+
19
21
  # Make whitespace in html tags consistent
20
22
  def normalise_html(html)
21
23
  Nokogiri::HTML5.fragment(html).to_s
22
24
  end
23
25
 
24
- def govspeak_to_html
25
- Govspeak::Document.new(govspeak_string, sanitize: false).to_html
26
+ def govspeak_to_html(sanitize:)
27
+ Govspeak::Document.new(
28
+ govspeak_string,
29
+ sanitize: sanitize,
30
+ allowed_image_hosts: @allowed_image_hosts,
31
+ ).to_html
26
32
  end
27
33
  end
@@ -17,7 +17,7 @@ module Govspeak
17
17
  def t(*args)
18
18
  options = args.last.is_a?(Hash) ? args.last.dup : {}
19
19
  key = args.shift
20
- I18n.t!(key, options.merge(locale: locale))
20
+ I18n.t!(key, **options.merge(locale: locale))
21
21
  end
22
22
 
23
23
  def format_with_html_line_breaks(string)
@@ -1,3 +1,3 @@
1
1
  module Govspeak
2
- VERSION = "6.7.7".freeze
2
+ VERSION = "6.8.1".freeze
3
3
  end
data/lib/govspeak.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "active_support"
1
2
  require "active_support/core_ext/hash"
2
3
  require "active_support/core_ext/array"
3
4
  require "erb"
@@ -53,6 +54,7 @@ module Govspeak
53
54
 
54
55
  @images = options.delete(:images) || []
55
56
  @allowed_elements = options.delete(:allowed_elements) || []
57
+ @allowed_image_hosts = options.delete(:allowed_image_hosts) || []
56
58
  @attachments = Array.wrap(options.delete(:attachments))
57
59
  @links = Array.wrap(options.delete(:links))
58
60
  @contacts = Array.wrap(options.delete(:contacts))
@@ -68,7 +70,8 @@ module Govspeak
68
70
  def to_html
69
71
  @to_html ||= begin
70
72
  html = if @options[:sanitize]
71
- HtmlSanitizer.new(kramdown_doc.to_html).sanitize(allowed_elements: @allowed_elements)
73
+ HtmlSanitizer.new(kramdown_doc.to_html, allowed_image_hosts: @allowed_image_hosts)
74
+ .sanitize(allowed_elements: @allowed_elements)
72
75
  else
73
76
  kramdown_doc.to_html
74
77
  end
@@ -464,9 +467,10 @@ module Govspeak
464
467
  end
465
468
 
466
469
  def add_acronym_alt_text(html)
467
- @acronyms.each do |acronym|
468
- html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
469
- end
470
+ # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now
471
+ # @acronyms.each do |acronym|
472
+ # html.gsub!(acronym[0], "<abbr title=\"#{acronym[1].strip}\">#{acronym[0]}</abbr>")
473
+ # end
470
474
  end
471
475
  end
472
476
  end
@@ -1048,43 +1048,44 @@ Teston
1048
1048
  )
1049
1049
  end
1050
1050
 
1051
- test_given_govspeak "
1052
- $LegislativeList
1053
- * 1. Item 1[^1] with an ACRONYM
1054
- * 2. Item 2[^2]
1055
- * 3. Item 3
1056
- $EndLegislativeList
1057
-
1058
- [^1]: Footnote definition one
1059
- [^2]: Footnote definition two with an ACRONYM
1060
-
1061
- *[ACRONYM]: This is the acronym explanation
1062
- " do
1063
- assert_html_output %(
1064
- <ol class="legislative-list">
1065
- <li>1. Item 1<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">[footnote 1]</a></sup> with an <abbr title="This is the acronym explanation">ACRONYM</abbr>
1066
- </li>
1067
- <li>2. Item 2<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>
1068
- </li>
1069
- <li>3. Item 3</li>
1070
- </ol>
1071
-
1072
- <div class="footnotes" role="doc-endnotes">
1073
- <ol>
1074
- <li id="fn:1" role="doc-endnote">
1075
- <p>
1076
- Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
1077
- </p>
1078
- </li>
1079
- <li id="fn:2" role="doc-endnote">
1080
- <p>
1081
- Footnote definition two with an <abbr title="This is the acronym explanation">ACRONYM</abbr><a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
1082
- </p>
1083
- </li>
1084
- </ol>
1085
- </div>
1086
- )
1087
- end
1051
+ # FIXME: this code is buggy and replaces abbreviations in HTML tags - removing the functionality for now
1052
+ # test_given_govspeak "
1053
+ # $LegislativeList
1054
+ # * 1. Item 1[^1] with an ACRONYM
1055
+ # * 2. Item 2[^2]
1056
+ # * 3. Item 3
1057
+ # $EndLegislativeList
1058
+ #
1059
+ # [^1]: Footnote definition one
1060
+ # [^2]: Footnote definition two with an ACRONYM
1061
+ #
1062
+ # *[ACRONYM]: This is the acronym explanation
1063
+ # " do
1064
+ # assert_html_output %(
1065
+ # <ol class="legislative-list">
1066
+ # <li>1. Item 1<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">[footnote 1]</a></sup> with an <abbr title="This is the acronym explanation">ACRONYM</abbr>
1067
+ # </li>
1068
+ # <li>2. Item 2<sup id="fnref:2" role="doc-noteref"><a href="#fn:2" class="footnote" rel="footnote">[footnote 2]</a></sup>
1069
+ # </li>
1070
+ # <li>3. Item 3</li>
1071
+ # </ol>
1072
+ #
1073
+ # <div class="footnotes" role="doc-endnotes">
1074
+ # <ol>
1075
+ # <li id="fn:1" role="doc-endnote">
1076
+ # <p>
1077
+ # Footnote definition one<a href="#fnref:1" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
1078
+ # </p>
1079
+ # </li>
1080
+ # <li id="fn:2" role="doc-endnote">
1081
+ # <p>
1082
+ # Footnote definition two with an <abbr title="This is the acronym explanation">ACRONYM</abbr><a href="#fnref:2" class="reversefootnote" role="doc-backlink" aria-label="go to where this is referenced">↩</a>
1083
+ # </p>
1084
+ # </li>
1085
+ # </ol>
1086
+ # </div>
1087
+ # )
1088
+ # end
1088
1089
 
1089
1090
  test_given_govspeak "
1090
1091
  The quick brown
data/test/test_helper.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require "simplecov"
2
- require "simplecov-rcov"
3
2
 
4
3
  SimpleCov.start
5
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
6
4
 
7
5
  $LOAD_PATH.unshift(File.expand_path("../lib")) unless $LOAD_PATH.include?(File.expand_path("../lib"))
8
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.7.7
4
+ version: 6.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-08 00:00:00.000000000 Z
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '7'
19
+ version: '6'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '5.0'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '7'
26
+ version: '6'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: addressable
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -194,16 +188,16 @@ dependencies:
194
188
  name: rubocop-govuk
195
189
  requirement: !ruby/object:Gem::Requirement
196
190
  requirements:
197
- - - "~>"
191
+ - - '='
198
192
  - !ruby/object:Gem::Version
199
- version: 4.2.0
193
+ version: 4.3.0
200
194
  type: :development
201
195
  prerelease: false
202
196
  version_requirements: !ruby/object:Gem::Requirement
203
197
  requirements:
204
- - - "~>"
198
+ - - '='
205
199
  - !ruby/object:Gem::Version
206
- version: 4.2.0
200
+ version: 4.3.0
207
201
  - !ruby/object:Gem::Dependency
208
202
  name: simplecov
209
203
  requirement: !ruby/object:Gem::Requirement
@@ -218,20 +212,6 @@ dependencies:
218
212
  - - ">="
219
213
  - !ruby/object:Gem::Version
220
214
  version: '0'
221
- - !ruby/object:Gem::Dependency
222
- name: simplecov-rcov
223
- requirement: !ruby/object:Gem::Requirement
224
- requirements:
225
- - - ">="
226
- - !ruby/object:Gem::Version
227
- version: '0'
228
- type: :development
229
- prerelease: false
230
- version_requirements: !ruby/object:Gem::Requirement
231
- requirements:
232
- - - ">="
233
- - !ruby/object:Gem::Version
234
- version: '0'
235
215
  description: |-
236
216
  A set of extensions to markdown layered on top of the kramdown
237
217
  library for use in the UK Government Single Domain project
@@ -340,36 +320,36 @@ required_ruby_version: !ruby/object:Gem::Requirement
340
320
  requirements:
341
321
  - - ">="
342
322
  - !ruby/object:Gem::Version
343
- version: '2.6'
323
+ version: '2.7'
344
324
  required_rubygems_version: !ruby/object:Gem::Requirement
345
325
  requirements:
346
326
  - - ">="
347
327
  - !ruby/object:Gem::Version
348
328
  version: '0'
349
329
  requirements: []
350
- rubygems_version: 3.0.3
330
+ rubygems_version: 3.3.9
351
331
  signing_key:
352
332
  specification_version: 4
353
333
  summary: Markup language for single domain
354
334
  test_files:
355
- - test/test_helper.rb
335
+ - test/govspeak_test_helper.rb
356
336
  - test/blockquote_extra_quote_remover_test.rb
357
- - test/govspeak_images_bang_test.rb
358
- - test/govspeak_contacts_test.rb
359
- - test/govspeak_table_with_headers_test.rb
360
337
  - test/govspeak_link_extractor_test.rb
361
- - test/govspeak_attachments_image_test.rb
362
- - test/html_validator_test.rb
363
- - test/govspeak_button_test.rb
338
+ - test/govspeak_images_test.rb
339
+ - test/govspeak_link_test.rb
364
340
  - test/govspeak_extract_contact_content_ids_test.rb
365
- - test/govspeak_test_helper.rb
366
341
  - test/govspeak_footnote_test.rb
367
- - test/govspeak_link_test.rb
342
+ - test/presenters/h_card_presenter_test.rb
343
+ - test/govspeak_attachments_inline_test.rb
368
344
  - test/govspeak_structured_headers_test.rb
345
+ - test/test_helper.rb
346
+ - test/govspeak_button_test.rb
347
+ - test/govspeak_attachment_test.rb
369
348
  - test/html_sanitizer_test.rb
370
- - test/govspeak_images_test.rb
349
+ - test/govspeak_contacts_test.rb
350
+ - test/govspeak_attachments_image_test.rb
351
+ - test/govspeak_images_bang_test.rb
371
352
  - test/govspeak_test.rb
353
+ - test/govspeak_table_with_headers_test.rb
354
+ - test/html_validator_test.rb
372
355
  - test/govspeak_attachment_link_test.rb
373
- - test/govspeak_attachment_test.rb
374
- - test/presenters/h_card_presenter_test.rb
375
- - test/govspeak_attachments_inline_test.rb