govuk_content_models 12.2.0 → 12.3.0
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md
CHANGED
@@ -18,21 +18,22 @@ class LinkValidator < ActiveModel::Validator
|
|
18
18
|
(\{:rel=["']external["']\})? # optional :rel=external in literal curly brackets.
|
19
19
|
}x
|
20
20
|
|
21
|
-
errors =
|
21
|
+
errors = Set.new
|
22
22
|
|
23
23
|
string.scan(link_regex) do |match|
|
24
24
|
|
25
|
-
|
26
|
-
'Internal links must start with a forward slash eg [link text](/link-destination). External links must start with http://, https://, or mailto: eg [external link text](https://www.google.co.uk)'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
if match[0] !~ %r{^(?:https?://|mailto:|/)}
|
26
|
+
errors << 'Internal links must start with a forward slash eg [link text](/link-destination). External links must start with http://, https://, or mailto: eg [external link text](https://www.google.co.uk).'
|
27
|
+
end
|
28
|
+
if match[1]
|
29
|
+
errors << %q-Don't include hover text in links. Delete the text in quotation marks eg "This appears when you hover over the link."-
|
30
|
+
end
|
31
|
+
if match[2]
|
32
|
+
errors << 'Delete {:rel="external"} in links.'
|
31
33
|
end
|
32
34
|
|
33
|
-
errors << error if error
|
34
35
|
end
|
35
|
-
errors
|
36
|
+
errors.to_a
|
36
37
|
end
|
37
38
|
|
38
39
|
protected
|
@@ -22,15 +22,25 @@ class LinkValidatorTest < ActiveSupport::TestCase
|
|
22
22
|
doc = Dummy.new(body: "abc [internal](/internal)")
|
23
23
|
assert doc.valid?
|
24
24
|
end
|
25
|
-
should "
|
26
|
-
doc = Dummy.new(body: 'abc [foobar](foobar.com "hover")')
|
25
|
+
should "not contain hover text" do
|
26
|
+
doc = Dummy.new(body: 'abc [foobar](http://foobar.com "hover")')
|
27
27
|
assert doc.invalid?
|
28
28
|
assert_includes doc.errors.keys, :body
|
29
29
|
end
|
30
|
-
should "
|
31
|
-
doc = Dummy.new(body: 'abc [foobar](foobar.com){:rel="external"}')
|
30
|
+
should "not set rel=external" do
|
31
|
+
doc = Dummy.new(body: 'abc [foobar](http://foobar.com){:rel="external"}')
|
32
32
|
assert doc.invalid?
|
33
33
|
assert_includes doc.errors.keys, :body
|
34
34
|
end
|
35
|
+
should "show multiple errors" do
|
36
|
+
doc = Dummy.new(body: 'abc [foobar](foobar.com "bar"){:rel="external"}')
|
37
|
+
assert doc.invalid?
|
38
|
+
assert_equal 3, doc.errors[:body].first.length
|
39
|
+
end
|
40
|
+
should "only show each error once" do
|
41
|
+
doc = Dummy.new(body: 'abc [link1](foobar.com), ghi [link2](bazquux.com)')
|
42
|
+
assert doc.invalid?
|
43
|
+
assert_equal 1, doc.errors[:body].first.length
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_content_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.
|
4
|
+
version: 12.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bson_ext
|
@@ -468,7 +468,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
468
468
|
version: '0'
|
469
469
|
segments:
|
470
470
|
- 0
|
471
|
-
hash: -
|
471
|
+
hash: -4200899125153312569
|
472
472
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
473
473
|
none: false
|
474
474
|
requirements:
|
@@ -477,7 +477,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
477
477
|
version: '0'
|
478
478
|
segments:
|
479
479
|
- 0
|
480
|
-
hash: -
|
480
|
+
hash: -4200899125153312569
|
481
481
|
requirements: []
|
482
482
|
rubyforge_project:
|
483
483
|
rubygems_version: 1.8.23
|