govspeak 5.2.0 → 5.2.1
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/govspeak/html_sanitizer.rb +1 -1
- data/lib/govspeak/version.rb +1 -1
- data/lib/govspeak.rb +2 -0
- data/test/govspeak_button_test.rb +8 -11
- data/test/html_sanitizer_test.rb +8 -0
- data/test/html_validator_test.rb +6 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec9f9ee71166be1a0eead7618adabb81efd51f4
|
4
|
+
data.tar.gz: cdc03d5927dac0271c21d8bba7dddbb565cccf27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02d24aa502bf2dbb098d03f07fe991b978f272e479ee2beaaab52bb7a4c6fd0927f9e52d40339ec8fd48c432eb316657ae1557f46d0bc8cb44bf9b06eab69844
|
7
|
+
data.tar.gz: 3cfbf2cc7011d73d4f35f223eb7c83946e7f1efba721a2a4f40e03ee1b5ffb75763a0a9671ae32e5c7a001d69c6437b5002ed8e0285ed3cd65f79583c8a65b31
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 5.2.1
|
2
|
+
* Fix validation to make sure buttons are considered valid
|
3
|
+
* Only allow buttons to be used on new lines, not when indented or inline within text (useful for guides) [#116](https://github.com/alphagov/govspeak/pull/116)
|
4
|
+
|
1
5
|
## 5.2.0
|
2
6
|
* Add button component for govspeak [#114](https://github.com/alphagov/govspeak/pull/114) see README for usage
|
3
7
|
|
data/lib/govspeak/version.rb
CHANGED
data/lib/govspeak.rb
CHANGED
@@ -136,6 +136,7 @@ module Govspeak
|
|
136
136
|
end
|
137
137
|
|
138
138
|
extension('button', %r{
|
139
|
+
^ # Match start of line only, allows for indenting code examples
|
139
140
|
{button(.*?)} # match opening bracket and capture attributes
|
140
141
|
\s* # any whitespace between opening bracket and link
|
141
142
|
\[ # match start of link markdown
|
@@ -146,6 +147,7 @@ module Govspeak
|
|
146
147
|
\) # match end of link text markdown
|
147
148
|
\s* # any whitespace between opening bracket and link
|
148
149
|
{\/button} # match ending bracket
|
150
|
+
$ # Match end of line only, allows for indenting code examples
|
149
151
|
}x) { |attributes, text, href|
|
150
152
|
button_classes = "button"
|
151
153
|
button_classes << " button-start" if attributes =~ /start/
|
@@ -45,17 +45,6 @@ class GovspeakTest < Minitest::Test
|
|
45
45
|
assert_html_output '<p>{button}I shouldn’t render a button{/button}</p>'
|
46
46
|
end
|
47
47
|
|
48
|
-
test_given_govspeak "Text before the button {button}[Start Now](http://www.gov.uk){/button} test after the button" do
|
49
|
-
# rubocop:disable Layout/TrailingWhitespace
|
50
|
-
assert_html_output %{
|
51
|
-
<p>Text before the button
|
52
|
-
<a role="button" class="button" href="http://www.gov.uk">Start Now</a>
|
53
|
-
test after the button</p>
|
54
|
-
}
|
55
|
-
# rubocop:enable Layout/TrailingWhitespace
|
56
|
-
assert_text_output "Text before the button Start Now test after the button"
|
57
|
-
end
|
58
|
-
|
59
48
|
test_given_govspeak "Text before the button with line breaks \n\n\n{button}[Start Now](http://www.gov.uk){/button}\n\n\n test after the button" do
|
60
49
|
assert_html_output %{
|
61
50
|
<p>Text before the button with line breaks</p>
|
@@ -82,4 +71,12 @@ class GovspeakTest < Minitest::Test
|
|
82
71
|
assert_html_output '<p><a role="button" class="button button-start" href="https://example.com/external-service/start-now" data-module="cross-domain-tracking" data-tracking-code="UA-XXXXXX-Y" data-tracking-name="govspeakButtonTracker">Start Now</a></p>'
|
83
72
|
assert_text_output "Start Now"
|
84
73
|
end
|
74
|
+
|
75
|
+
# Test indenting button govspeak results in no render, useful in guides
|
76
|
+
test_given_govspeak " {button start cross-domain-tracking:UA-XXXXXX-Y}[Example](https://example.com/external-service/start-now){/button}" do
|
77
|
+
assert_html_output %{
|
78
|
+
<pre><code>{button start cross-domain-tracking:UA-XXXXXX-Y}[Example](https://example.com/external-service/start-now){/button}
|
79
|
+
</code></pre>
|
80
|
+
}
|
81
|
+
end
|
85
82
|
end
|
data/test/html_sanitizer_test.rb
CHANGED
@@ -28,6 +28,14 @@ class HtmlSanitizerTest < Minitest::Test
|
|
28
28
|
assert_equal "Fortnum & Mason", Govspeak::HtmlSanitizer.new(html).sanitize
|
29
29
|
end
|
30
30
|
|
31
|
+
test "allow govspeak button markup" do
|
32
|
+
html = "<a href='#' data-module='cross-domain-tracking' data-tracking-code='UA-XXXXXX-Y' data-tracking-name='govspeakButtonTracker'></a>"
|
33
|
+
assert_equal(
|
34
|
+
"<a href=\"#\" data-module=\"cross-domain-tracking\" data-tracking-code=\"UA-XXXXXX-Y\" data-tracking-name=\"govspeakButtonTracker\"></a>",
|
35
|
+
Govspeak::HtmlSanitizer.new(html).sanitize
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
31
39
|
test "allows images on whitelisted domains" do
|
32
40
|
html = "<img src='http://allowed.com/image.jgp'>"
|
33
41
|
sanitized_html = Govspeak::HtmlSanitizer.new(html, allowed_image_hosts: ['allowed.com']).sanitize
|
data/test/html_validator_test.rb
CHANGED
@@ -95,4 +95,10 @@ class HtmlValidatorTest < Minitest::Test
|
|
95
95
|
html = "<div class=\"govspeak\"><h2 id=\"some-title\">\n<span class=\"number\">1. </span> Some title</h2>\n\n<p>Some text</p>\n</div>"
|
96
96
|
assert Govspeak::HtmlValidator.new(html).valid?
|
97
97
|
end
|
98
|
+
|
99
|
+
test "allow govspeak button" do
|
100
|
+
assert Govspeak::HtmlValidator.new("{button}[Start now](https://gov.uk){/button}").valid?
|
101
|
+
assert Govspeak::HtmlValidator.new("{button start}[Start now](https://gov.uk){/button}").valid?
|
102
|
+
assert Govspeak::HtmlValidator.new("{button start cross-domain-tracking:UA-XXXXXX-Y}[Start now](https://gov.uk){/button}").valid?
|
103
|
+
end
|
98
104
|
end
|
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: 5.2.
|
4
|
+
version: 5.2.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: 2017-11-
|
12
|
+
date: 2017-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: kramdown
|
@@ -320,18 +320,18 @@ signing_key:
|
|
320
320
|
specification_version: 4
|
321
321
|
summary: Markup language for single domain
|
322
322
|
test_files:
|
323
|
-
- test/blockquote_extra_quote_remover_test.rb
|
324
323
|
- test/govspeak_test_helper.rb
|
325
|
-
- test/
|
324
|
+
- test/govspeak_test.rb
|
326
325
|
- test/govspeak_attachments_image_test.rb
|
327
|
-
- test/
|
326
|
+
- test/with_deep_merge_test.rb
|
327
|
+
- test/govspeak_link_test.rb
|
328
328
|
- test/test_helper.rb
|
329
|
-
- test/
|
329
|
+
- test/html_validator_test.rb
|
330
|
+
- test/blockquote_extra_quote_remover_test.rb
|
330
331
|
- test/html_sanitizer_test.rb
|
332
|
+
- test/govspeak_attachments_test.rb
|
331
333
|
- test/govspeak_button_test.rb
|
332
|
-
- test/
|
333
|
-
- test/html_validator_test.rb
|
334
|
-
- test/govspeak_test.rb
|
335
|
-
- test/govspeak_link_test.rb
|
336
|
-
- test/govspeak_contacts_test.rb
|
334
|
+
- test/govspeak_structured_headers_test.rb
|
337
335
|
- test/presenters/h_card_presenter_test.rb
|
336
|
+
- test/govspeak_contacts_test.rb
|
337
|
+
- test/govspeak_attachments_inline_test.rb
|