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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/berns.rb +16 -0
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3419a2a4871c87d37d3438a20d84fef58e6ad33e4d02070665693412c5a234ee
4
- data.tar.gz: 2b2bd7b76e83b1d2b67edb9b79ab1a32bd615b31c8742ea2a3344cd9a991b35f
3
+ metadata.gz: 675a795e6f002f4a7a01d8f0cf2212cf700ee532cbfc6f931ac8da70916549c9
4
+ data.tar.gz: 26f950193def91bbe73e1bf6aee8a5976b91093aa6c4b627463bdf519724bdbc
5
5
  SHA512:
6
- metadata.gz: b9d7168b83fe3152fee3fdf835af7baf48635f89c5c223042f9aa28e6dc8a0b67fa6328c3fcc055cb26d1f9705de02e263326eed70bd466348aa51f2a141cf43
7
- data.tar.gz: 87edf947bbbe461aebc17c9c8189ee70e5241eceb82919a10f151c9589887a7b3c9d4f663432fb6f4470d546c69b50252fecd3305a0ba24639630664b9f3d7cb
6
+ metadata.gz: 0bf3f0367bc6d49a93c623a3974646dbcbeb67999dc336fd03e8b3cab6610e804e2975e981a522c007e363ba03aed3c8b8e819186f47dfc95de811714e51307a
7
+ data.tar.gz: 643b84ca007b078b79339f83a505e0aabd62bb0beca30890bb8fb4fb9451a8a63a052eec2abbc28127bdc5a504fb98b5d71ea8e7db095fc16f3292bb0c75f424
@@ -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.0.0
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-03-18 00:00:00.000000000 Z
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.3
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.