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 +4 -4
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/lib/trenni/sanitize/filter.rb +1 -1
- data/lib/trenni/sanitize/text.rb +17 -0
- data/lib/trenni/sanitize/version.rb +1 -1
- data/spec/trenni/sanitize/text_spec.rb +43 -0
- data/trenni-sanitize.gemspec +1 -1
- metadata +7 -8
- data/.simplecov +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af6bc3fd66dd571a303a216442d9f8abf2e51e28693da8798107bcb540f32f85
|
4
|
+
data.tar.gz: af2f9d45d17c77128d6ed553e6512a0e3345195c867419286ccd527435ee235f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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://
|
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
|
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 => :
|
19
|
+
task :default => :spec
|
data/lib/trenni/sanitize/text.rb
CHANGED
@@ -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
|
|
@@ -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
|
data/trenni-sanitize.gemspec
CHANGED
@@ -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"
|
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.
|
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-
|
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: '
|
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: '
|
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.
|
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.
|