berns 1.0.0 → 1.1.0
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 +4 -4
- data/lib/berns.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 675a795e6f002f4a7a01d8f0cf2212cf700ee532cbfc6f931ac8da70916549c9
|
|
4
|
+
data.tar.gz: 26f950193def91bbe73e1bf6aee8a5976b91093aa6c4b627463bdf519724bdbc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0bf3f0367bc6d49a93c623a3974646dbcbeb67999dc336fd03e8b3cab6610e804e2975e981a522c007e363ba03aed3c8b8e819186f47dfc95de811714e51307a
|
|
7
|
+
data.tar.gz: 643b84ca007b078b79339f83a505e0aabd62bb0beca30890bb8fb4fb9451a8a63a052eec2abbc28127bdc5a504fb98b5d71ea8e7db095fc16f3292bb0c75f424
|
data/lib/berns.rb
CHANGED
|
@@ -4,6 +4,9 @@ module Berns
|
|
|
4
4
|
SPACE = ' '
|
|
5
5
|
EMPTY = ''
|
|
6
6
|
|
|
7
|
+
# Regular expression for basic HTML tag sanitizing.
|
|
8
|
+
SANITIZE_REGEX = /<[^>]+>/.freeze
|
|
9
|
+
|
|
7
10
|
# Full list of void elements - http://xahlee.info/js/html5_non-closing_tag.html
|
|
8
11
|
VOID = %i[area base br col embed hr img input link menuitem meta param source track wbr].freeze
|
|
9
12
|
|
|
@@ -24,6 +27,19 @@ module Berns
|
|
|
24
27
|
end
|
|
25
28
|
end
|
|
26
29
|
|
|
30
|
+
# Sanitize text input by stripping HTML tags.
|
|
31
|
+
#
|
|
32
|
+
# @example Sanitize some text, removing HTML elements.
|
|
33
|
+
# sanitize('This <span>should be clean</span>') # => "This should be clean"
|
|
34
|
+
#
|
|
35
|
+
# @param text [String]
|
|
36
|
+
# The string to sanitize.
|
|
37
|
+
# @return [nil, String]
|
|
38
|
+
# nil unless a string was passed in, otherwise the sanitized string.
|
|
39
|
+
def self.sanitize(string)
|
|
40
|
+
string&.gsub(SANITIZE_REGEX, EMPTY)
|
|
41
|
+
end
|
|
42
|
+
|
|
27
43
|
# Generate a simple HTML element.
|
|
28
44
|
#
|
|
29
45
|
# @example Create an element with simple attributes.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: berns
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Taylor Beck
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2019-
|
|
12
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
83
83
|
- !ruby/object:Gem::Version
|
|
84
84
|
version: '0'
|
|
85
85
|
requirements: []
|
|
86
|
-
rubygems_version: 3.0.
|
|
86
|
+
rubygems_version: 3.0.4
|
|
87
87
|
signing_key:
|
|
88
88
|
specification_version: 4
|
|
89
89
|
summary: A utility library for generating HTML strings.
|