trenni-sanitize 0.3.0 → 0.4.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: 692099586ce2e3dfb2e1ff3911cafa0e39a22d5dac957ef4401f3fd31be32565
4
- data.tar.gz: d0a4d9ff3f8e5937119f08638b188c6d7c386fa428fb3c98fe64334d8fd8e705
3
+ metadata.gz: af6bc3fd66dd571a303a216442d9f8abf2e51e28693da8798107bcb540f32f85
4
+ data.tar.gz: af2f9d45d17c77128d6ed553e6512a0e3345195c867419286ccd527435ee235f
5
5
  SHA512:
6
- metadata.gz: 4668acf3447f634251f01a4b3ffef72592552ff6da12178b7201a221e25b6dc1f0f6115903201ad75532e73d6df93dda13cb8e4cb68a890e651569710700852c
7
- data.tar.gz: bde8b725c3a2455b3eb762eb25036538d4a591aa77e3e6e5c30642a8680f3907fd4f429c906e893b70401b1e7b9b1616dd4153f38d7c0533dfc698351658aebe
6
+ metadata.gz: 24187244b0995b0a83f5fcf93d7c215514517456894b0523a3d60c51f46729993c4d1fdce35fa1ab1982fb68cc8838bfb6f532df0c73a016cd8f14c4cd0e33ae
7
+ data.tar.gz: cc6468c2fdaf2a2b5d396378a442a017cf3e64c75cb3fa56e26ffb21dc91e54d70adbde423c38e77ddd2b27322c591bd775c9ab0197412c42836a022766a03ff
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Sanitize markup by adding, changing or removing tags, using the [trenni] stream processor (which has a naive C implementation).
4
4
 
5
- [![Build Status](https://secure.travis-ci.org/ioquatix/trenni-sanitize.svg)](http://travis-ci.org/ioquatix/trenni-sanitize)
5
+ [![Build Status](https://travis-ci.com/ioquatix/trenni-sanitize.svg)](https://travis-ci.com/ioquatix/trenni-sanitize)
6
6
  [![Code Climate](https://codeclimate.com/github/ioquatix/trenni-sanitize.svg)](https://codeclimate.com/github/ioquatix/trenni-sanitize)
7
7
  [![Coverage Status](https://coveralls.io/repos/ioquatix/trenni-sanitize/badge.svg)](https://coveralls.io/r/ioquatix/trenni-sanitize)
8
8
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rspec/core/rake_task"
4
4
  # Load all rake tasks:
5
5
  import(*Dir.glob('tasks/**/*.rake'))
6
6
 
7
- RSpec::Core::RakeTask.new(:test)
7
+ RSpec::Core::RakeTask.new
8
8
 
9
9
  task :environment do
10
10
  $LOAD_PATH.unshift File.expand_path('lib', __dir__)
@@ -16,4 +16,4 @@ task :console => :environment do
16
16
  Pry.start
17
17
  end
18
18
 
19
- task :default => :test
19
+ task :default => :spec
@@ -64,7 +64,7 @@ module Trenni
64
64
  end
65
65
 
66
66
  def [] key
67
- self.tag.attributes[key]
67
+ self.tag&.attributes[key]
68
68
  end
69
69
  end
70
70
 
@@ -23,7 +23,16 @@ require_relative 'filter'
23
23
  module Trenni
24
24
  module Sanitize
25
25
  class Text < Filter
26
+ CLOSING = {
27
+ "p" => "\n\n",
28
+ "div" => "\n\n",
29
+ }
30
+
26
31
  def filter(node)
32
+ if node.name == "br"
33
+ text("\n\n")
34
+ end
35
+
27
36
  if node.name == 'script'
28
37
  node.skip!(ALL) # Skip everything including content.
29
38
  else
@@ -31,6 +40,14 @@ module Trenni
31
40
  end
32
41
  end
33
42
 
43
+ def close_tag(name, offset = nil)
44
+ super
45
+
46
+ if value = CLOSING[name]
47
+ text(value)
48
+ end
49
+ end
50
+
34
51
  def doctype(string)
35
52
  end
36
53
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Trenni
22
22
  module Sanitize
23
- VERSION = "0.3.0"
23
+ VERSION = "0.4.0"
24
24
  end
25
25
  end
@@ -0,0 +1,43 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'trenni/sanitize/text'
22
+
23
+ RSpec.describe Trenni::Sanitize::Text do
24
+ let(:text) {"One\n\nTwo\n\nThree\n\n"}
25
+
26
+ it "passes through plain text unchanged" do
27
+ fragment = described_class.parse(text)
28
+
29
+ expect(fragment.output).to be == text
30
+ end
31
+
32
+ it "should extract text" do
33
+ fragment = described_class.parse("<p onclick='malicious()'>Hello World</p><script>doot()</script>")
34
+
35
+ expect(fragment.output).to be == "Hello World\n\n"
36
+ end
37
+
38
+ it "replaces line breaks" do
39
+ fragment = described_class.parse("One<br/>Two<br/>Three")
40
+
41
+ expect(fragment.output).to be == "One\n\nTwo\n\nThree"
42
+ end
43
+ end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "trenni", '~> 3.5'
21
21
 
22
22
  spec.add_development_dependency "covered"
23
- spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rspec", "~> 3.4"
25
25
  spec.add_development_dependency "rake"
26
26
  end
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.3.0
4
+ version: 0.4.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-04-05 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +89,6 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
- - ".simplecov"
93
92
  - ".travis.yml"
94
93
  - Gemfile
95
94
  - README.md
@@ -125,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  - !ruby/object:Gem::Version
126
125
  version: '0'
127
126
  requirements: []
128
- rubygems_version: 3.0.3
127
+ rubygems_version: 3.0.4
129
128
  signing_key:
130
129
  specification_version: 4
131
130
  summary: Sanitize markdown according to a set of rules.
data/.simplecov DELETED
@@ -1,9 +0,0 @@
1
-
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- if ENV['TRAVIS']
7
- require 'coveralls'
8
- Coveralls.wear!
9
- end