trenni-sanitize 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af6bc3fd66dd571a303a216442d9f8abf2e51e28693da8798107bcb540f32f85
4
- data.tar.gz: af2f9d45d17c77128d6ed553e6512a0e3345195c867419286ccd527435ee235f
3
+ metadata.gz: be872bc0f1f2f9b2fca5c5a8738090aea3faf1f2880b9201447edad78419f0ab
4
+ data.tar.gz: 822005447509aaabe1c4ee6fbc9b97fe17c7b4eb7f7f9faa7e0697e394e955be
5
5
  SHA512:
6
- metadata.gz: 24187244b0995b0a83f5fcf93d7c215514517456894b0523a3d60c51f46729993c4d1fdce35fa1ab1982fb68cc8838bfb6f532df0c73a016cd8f14c4cd0e33ae
7
- data.tar.gz: cc6468c2fdaf2a2b5d396378a442a017cf3e64c75cb3fa56e26ffb21dc91e54d70adbde423c38e77ddd2b27322c591bd775c9ab0197412c42836a022766a03ff
6
+ metadata.gz: 70651108fffab5e259895627a312b9eadfa66233c8f6f7e0ec8de4f56cdfe0bf7cbec26d6ca88d4db3ad1e0be24c664282a1f3d932e73b7336b0054a305a790d
7
+ data.tar.gz: 31c18d416cc9735cdf39e4b348b854db3a81a06041e66fcbcd87970165ba8b08e2a7b491f0f617aa5e58d051a66337a5dca4040c17f53f55f706dfe032355916
@@ -4,7 +4,6 @@ cache: bundler
4
4
 
5
5
  matrix:
6
6
  include:
7
- - rvm: 2.3
8
7
  - rvm: 2.4
9
8
  - rvm: 2.5
10
9
  - rvm: 2.6
@@ -12,6 +11,7 @@ matrix:
12
11
  os: osx
13
12
  - rvm: 2.6
14
13
  env: COVERAGE=BriefSummary,Coveralls
14
+ - rvm: 2.7
15
15
  - rvm: truffleruby
16
16
  - rvm: jruby-head
17
17
  env: JRUBY_OPTS="--debug -X+O"
@@ -18,8 +18,5 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require_relative 'sanitize/extensions'
22
-
23
21
  require_relative 'sanitize/text'
24
22
  require_relative 'sanitize/fragment'
25
-
@@ -66,6 +66,10 @@ module Trenni
66
66
  def [] key
67
67
  self.tag&.attributes[key]
68
68
  end
69
+
70
+ def limit_attributes(keys)
71
+ self.tag&.attributes&.select!{|key, value| keys.include?(key)}
72
+ end
69
73
  end
70
74
 
71
75
  def initialize(output, entities)
@@ -116,11 +120,11 @@ module Trenni
116
120
 
117
121
  @current = Node.new(name, tag, current.skip)
118
122
  end
119
-
123
+
120
124
  def attribute(key, value)
121
125
  @current.tag.attributes[key] = value
122
126
  end
123
-
127
+
124
128
  def open_tag_end(self_closing)
125
129
  if self_closing
126
130
  @current.tag.closed = true
@@ -135,7 +139,7 @@ module Trenni
135
139
  # If the tag was self-closing, it's no longer current at this point, we are back in the context of the parent tag.
136
140
  @current = self.top if self_closing
137
141
  end
138
-
142
+
139
143
  def close_tag(name, offset = nil)
140
144
  while node = @stack.pop
141
145
  node.tag.write_closing_tag(@output) unless node.skip? TAG
@@ -153,19 +157,19 @@ module Trenni
153
157
  def doctype(string)
154
158
  @output << string unless current.skip? DOCTYPE
155
159
  end
156
-
160
+
157
161
  def comment(string)
158
162
  @output << string unless current.skip? COMMENT
159
163
  end
160
-
164
+
161
165
  def instruction(string)
162
166
  @output << string unless current.skip? INSTRUCTION
163
167
  end
164
-
168
+
165
169
  def cdata(string)
166
170
  @output << string unless current.skip? CDATA
167
171
  end
168
-
172
+
169
173
  def text(string)
170
174
  Markup.append(@output, string) unless current.skip? TEXT
171
175
  end
@@ -20,10 +20,12 @@
20
20
 
21
21
  require_relative 'filter'
22
22
 
23
+ require 'set'
24
+
23
25
  module Trenni
24
26
  module Sanitize
25
27
  class Fragment < Filter
26
- STANDARD_ATTRIBUTES = ['class', 'style'].freeze
28
+ STANDARD_ATTRIBUTES = Set.new(['class', 'style']).freeze
27
29
 
28
30
  ALLOWED_TAGS = {
29
31
  'div' => STANDARD_ATTRIBUTES,
@@ -49,7 +51,7 @@ module Trenni
49
51
 
50
52
  def filter(node)
51
53
  if attributes = ALLOWED_TAGS[node.name]
52
- node.tag.attributes.slice!(*attributes)
54
+ node.limit_attributes(attributes)
53
55
 
54
56
  node.accept!
55
57
  else
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Trenni
22
22
  module Sanitize
23
- VERSION = "0.4.0"
23
+ VERSION = "0.5.0"
24
24
  end
25
25
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ["lib"]
17
17
 
18
- spec.required_ruby_version = '~> 2.1'
18
+ spec.required_ruby_version = '~> 2.4'
19
19
 
20
20
  spec.add_dependency "trenni", '~> 3.5'
21
21
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni-sanitize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-18 00:00:00.000000000 Z
11
+ date: 2020-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni
@@ -94,14 +94,12 @@ files:
94
94
  - README.md
95
95
  - Rakefile
96
96
  - lib/trenni/sanitize.rb
97
- - lib/trenni/sanitize/extensions.rb
98
97
  - lib/trenni/sanitize/filter.rb
99
98
  - lib/trenni/sanitize/fragment.rb
100
99
  - lib/trenni/sanitize/text.rb
101
100
  - lib/trenni/sanitize/version.rb
102
101
  - spec/spec_helper.rb
103
102
  - spec/trenni/sanitize/benchmark_spec.rb
104
- - spec/trenni/sanitize/extensions_spec.rb
105
103
  - spec/trenni/sanitize/fragment_spec.rb
106
104
  - spec/trenni/sanitize/sample.html
107
105
  - spec/trenni/sanitize/text_spec.rb
@@ -117,21 +115,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
115
  requirements:
118
116
  - - "~>"
119
117
  - !ruby/object:Gem::Version
120
- version: '2.1'
118
+ version: '2.4'
121
119
  required_rubygems_version: !ruby/object:Gem::Requirement
122
120
  requirements:
123
121
  - - ">="
124
122
  - !ruby/object:Gem::Version
125
123
  version: '0'
126
124
  requirements: []
127
- rubygems_version: 3.0.4
125
+ rubygems_version: 3.1.2
128
126
  signing_key:
129
127
  specification_version: 4
130
128
  summary: Sanitize markdown according to a set of rules.
131
129
  test_files:
132
130
  - spec/spec_helper.rb
133
131
  - spec/trenni/sanitize/benchmark_spec.rb
134
- - spec/trenni/sanitize/extensions_spec.rb
135
132
  - spec/trenni/sanitize/fragment_spec.rb
136
133
  - spec/trenni/sanitize/sample.html
137
134
  - spec/trenni/sanitize/text_spec.rb
@@ -1,14 +0,0 @@
1
-
2
- class Hash
3
- unless defined?(slice)
4
- def slice(*keys)
5
- self.select{|key, value| keys.include? key}
6
- end
7
- end
8
-
9
- unless defined?(slice!)
10
- def slice!(*keys)
11
- self.select!{|key, value| keys.include? key}
12
- end
13
- end
14
- end
@@ -1,26 +0,0 @@
1
-
2
- require 'trenni/sanitize/extensions'
3
-
4
- RSpec.describe Hash do
5
- let(:hash) {{x: 10, y: 20, z: 30}}
6
-
7
- it "can slice the hash" do
8
- result = hash.slice(:x)
9
-
10
- expect(hash.size).to be == 3
11
- expect(result.size).to be == 1
12
-
13
- expect(result[:x]).to be == 10
14
- expect(result[:y]).to be_nil
15
- expect(result[:z]).to be_nil
16
- end
17
-
18
- it "can slice! the hash in-place" do
19
- hash.slice!(:x)
20
-
21
- expect(hash.size).to be == 1
22
- expect(hash[:x]).to be == 10
23
- expect(hash[:y]).to be_nil
24
- expect(hash[:z]).to be_nil
25
- end
26
- end