escape_escape_escape 0.3.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+
2
+
3
+ it 'returns string if valid'
4
+ input '#my_box div.hello:hover'
5
+ output '#my_box div.hello:hover'
6
+
7
+
8
+ it 'raises Invalid if it contains unallowed chars:'
9
+ input '$my_box'
10
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
11
+
12
+
@@ -0,0 +1,53 @@
1
+
2
+ it 'sanitizes :css :expression regardless of the case'
3
+ input "eXprEssioN(alert('xss!'));"
4
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
5
+
6
+ it 'sanitizes :css :expression when ( or ) is an html entity: ( )'
7
+ input "eXprEssioN(alert('xss!'))"
8
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
9
+
10
+
11
+ it 'sanitizes :css :expression when ( is html entity regardless of case: &rPaR;'
12
+ input "eXprEssioN&rPaR;alert('xss!'))"
13
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
14
+
15
+ it 'sanitizes css_href'
16
+ input "smtp://file.com/img.png"
17
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
18
+
19
+ it 'sanitizes css_href event if slash is html entity: /'
20
+ input "smtp://file.com/img.png"
21
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
22
+
23
+ it 'sanitizes css_href event if slash is html entity: /'
24
+ input "smtp://file.com/img.png"
25
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
26
+
27
+
28
+ it 'sanitizes css_href event if slash is html entity: /'
29
+ input "smtp://file.com/img.png"
30
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
31
+
32
+ it 'sanitizes css_href with encoded slashes'
33
+ input "smtp://file.com/img.png"
34
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
35
+
36
+ it 'sanitizes javascript: href'
37
+ input 'jAvAscript://alert()'
38
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
39
+
40
+ it 'sanitizes javascript: href with encoded colons:'
41
+ input "javascript://alert()"
42
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
43
+
44
+ it 'sanitizes javascript: href with encoded slashes'
45
+ input "javascript://alert()"
46
+ raises Escape_Escape_Escape::Invalid, /contains invalid chars/
47
+
48
+ it 'returns cleaned string'
49
+ input '1px solid #000'
50
+ output '1px solid #000'
51
+
52
+
53
+
@@ -0,0 +1,5 @@
1
+
2
+ it 'has the same REGEX_UNSUITABLE_CHARS as Sanitize'
3
+ input Escape_Escape_Escape::REGEX_UNSUITABLE_CHARS
4
+ output Sanitize::REGEX_UNSUITABLE_CHARS
5
+
@@ -0,0 +1,118 @@
1
+
2
+
3
+ it "raises Invalid_HREF if scheme is whitespace padded:"
4
+ input "javascript ://alert()"
5
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
6
+
7
+
8
+ it "raises Invalid_HREF if scheme is whitespace padded, slash encoded:"
9
+ input "javascript :&sOL;/alert()"
10
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
11
+
12
+
13
+ it "raises Invalid_HREF if colon encode: : :"
14
+ input "javascript://alert()"
15
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
16
+
17
+
18
+ it "raises Invalid_HREF if colon encode: : :"
19
+ input "javascript://alert()"
20
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
21
+
22
+
23
+ it "raises Invalid_HREF if colon encode: : :"
24
+ input "javascript://alert()"
25
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
26
+
27
+
28
+ it "raises Invalid_HREF if string is whitespace padded:"
29
+ input " javascript://alert() "
30
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
31
+
32
+
33
+ it "raises Invalid_HREF if string is whitespace padded, multi-case:"
34
+ input " javaSCript ://alert() "
35
+ raises Escape_Escape_Escape::Invalid_HREF, /javaSCript/i
36
+
37
+
38
+ it "escapes valid /path"
39
+ input "/path/mine/&"
40
+ output "/path/mine/&"
41
+
42
+
43
+ it "raises Invalid_HREF if invalid uri:"
44
+ input "javascript:alert(s)"
45
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
46
+
47
+ it "raises Invalid_HREF if invalid uri"
48
+ input "javascript:alert(s)"
49
+ raises Escape_Escape_Escape::Invalid_HREF, /javascript/
50
+
51
+ it "escapes valid https uri"
52
+ input "https://www.yahoo.com/&"
53
+ output "https://www.yahoo.com/&"
54
+
55
+
56
+ it "escapes valid uri"
57
+ input "http://www.yahoo.com/&"
58
+ output "http://www.yahoo.com/&"
59
+
60
+
61
+ it "escapes valid relative path:"
62
+ input "/path/mine/&"
63
+ output "/path/mine/&"
64
+
65
+
66
+ it "raises Invalid_HREF if it contains unicode:"
67
+ input "http://кц.рф"
68
+ raises Escape_Escape_Escape::Invalid_HREF, /bad URI/
69
+
70
+
71
+ it 'normalizes address:'
72
+ input "hTTp://wWw.test.com/"
73
+ output "http://wWw.test.com/"
74
+
75
+
76
+ it 'fails w/ Invalid_HREF if invalid uri: < :'
77
+ input "http://www.test.com/<something/"
78
+ raises Escape_Escape_Escape::Invalid_HREF, /http:\/\/www.test.com\/<something\//
79
+
80
+
81
+ it 'returns html escaped chars: \' :'
82
+ input "http://www.test.com/?test='something/"
83
+ output "http:&#47;&#47;www.test.com&#47;?test=&#39;something&#47;"
84
+
85
+
86
+ it 'fails w/ Invalid_HREF if HTML entities in uri:'
87
+ input "http://6&#9;6.000146.0x7.147/"
88
+ raises Escape_Escape_Escape::Invalid_HREF, /bad URI/
89
+
90
+
91
+ it 'fails w/ Invalid_HREF if path contains html entities:'
92
+ input "http://www.test.com/&nbsp;s/"
93
+ raises Escape_Escape_Escape::Invalid_HREF, /bad URI/
94
+
95
+
96
+ it 'fails w/ Invalid_HREF if query string contains HTML entities:'
97
+ input "http://www.test.com/s/test?t&nbsp;test"
98
+ raises Escape_Escape_Escape::Invalid_HREF, /bad URI/
99
+
100
+
101
+
102
+ it 'does not re-escaped already escaped :href'
103
+ input "http:&#47;&#47;www.example.com&#47;"
104
+ output "http:&#47;&#47;www.example.com&#47;"
105
+
106
+
107
+ it 'lower-cases scheme'
108
+ input "hTTp://www.example.com/"
109
+ output "http:&#47;&#47;www.example.com&#47;"
110
+
111
+
112
+ it 'fails w/ Invalid_HREF if contains &sol;, regardless of case:'
113
+ input "htTp:&soL;&sOl;file.com/img.png"
114
+ raises Escape_Escape_Escape::Invalid_HREF, /address is invalid/
115
+
116
+
117
+
118
+
@@ -0,0 +1,34 @@
1
+ it "replaces tabs with 2 spaces"
2
+ input "<p>hello\tagain</p>"
3
+ output "<p>hello again</p>"
4
+
5
+ it "removes \\r"
6
+ input "hi \r\r again"
7
+ output "hi again"
8
+
9
+ it "does not remove \\n"
10
+ input "<p>hello\nagain</p>"
11
+ output "<p>hello\nagain</p>"
12
+
13
+ it "does not remove multiple \\n"
14
+ input "<p>hello\n \nagain</p>"
15
+ output "<p>hello\n \nagain</p>"
16
+
17
+ it "normalizes string"
18
+ input "Ⅷ"
19
+ output "VIII"
20
+
21
+ it "normalizes string"
22
+ input "\u2167"
23
+ output "VIII"
24
+
25
+
26
+ it "replaces nb spaces (160 codepoint) with regular ' ' spaces"
27
+ input [160, 160,64, 116, 119, 101, 108, 108, 121, 109, 101, 160, 102, 105, 108, 109].
28
+ inject('', :<<)
29
+
30
+ output "@twellyme film"
31
+
32
+ it "replaces tabs with spaces"
33
+ input "a\t \ta"
34
+ output "a a"
@@ -0,0 +1,41 @@
1
+
2
+
3
+
4
+ it 'turns numerics into strings: 1.004'
5
+ input 1.004
6
+ output '1.004'
7
+
8
+
9
+ it 'raises Invalid if Object'
10
+ input Object.new
11
+ raises Escape_Escape_Escape::Invalid, /Not a String, Number, Array, or Hash/i
12
+
13
+
14
+ it 'escapes all String keys in nested objects'
15
+ input({" a >" => {" a > " => "<b>test</b>"}})
16
+ output({
17
+ "a &gt;" => {
18
+ "a &gt;" => "&lt;b&gt;test&lt;&#47;b&gt;"
19
+ }
20
+ })
21
+
22
+
23
+ it 'escapes all Symbol keys in nested objects'
24
+ input({:" a > " => {:" a >" => "<b>test</b>"}})
25
+ output({
26
+ :"a &gt;" => {
27
+ :"a &gt;" => "&lt;b&gt;test&lt;&#47;b&gt;"
28
+ }
29
+ })
30
+
31
+
32
+
33
+ it 'escapes all values in nested objects'
34
+ input( {name: {name: "<b>test</b>"}} )
35
+ output( {name: {name: "&lt;b&gt;test&lt;&#47;b&gt;"}} )
36
+
37
+
38
+
39
+ it 'escapes all values in nested arrays'
40
+ input [{name:{name: '<b>test</b>'}}]
41
+ output [{name: {name: "&lt;b&gt;test&lt;&#47;b&gt;"}}]
@@ -1,35 +1,147 @@
1
1
 
2
+ require 'Bacon_Colored'
3
+ require 'escape_escape_escape'
4
+ require 'pry'
5
+
2
6
  require "multi_json"
3
7
  require "escape_escape_escape"
8
+ require 'sanitize'
9
+
10
+ BRACKETS = <<-EOF.split.join(' ')
11
+ < %3C &lt &lt; &LT &LT; &#60 &#060 &#0060
12
+ &#00060 &#000060 &#0000060 &#60; &#060; &#0060; &#00060;
13
+ &#000060; &#0000060; &#x3c &#x03c &#x003c &#x0003c &#x00003c
14
+ &#x000003c &#x3c; &#x03c; &#x003c; &#x0003c; &#x00003c;
15
+ &#x000003c; &#X3c &#X03c &#X003c &#X0003c &#X00003c &#X000003c
16
+ &#X3c; &#X03c; &#X003c; &#X0003c; &#X00003c; &#X000003c;
17
+ &#x3C &#x03C &#x003C &#x0003C &#x00003C &#x000003C &#x3C; &#x03C;
18
+ &#x003C; &#x0003C; &#x00003C; &#x000003C; &#X3C &#X03C
19
+ &#X003C &#X0003C &#X00003C &#X000003C &#X3C; &#X03C; &#X003C; &#X0003C;
20
+ &#X00003C; &#X000003C; \x3c \x3C \u003c \u003C
21
+ EOF
22
+
23
+
24
+ class It_Dsl
25
+ class << self
26
+
27
+ def tests
28
+ @tests ||= []
29
+ end
30
+
31
+ def args
32
+ @args ||= []
33
+ end
34
+
35
+ def describe str
36
+ tests << {:describe => str, :tests=>[]}
37
+ end
38
+
39
+ def it str
40
+ args << str
41
+ end
42
+
43
+ def input o
44
+ args << o
45
+ end
46
+
47
+ def << t
48
+ if !args.empty?
49
+ fail "Unknown values pending for: #{tests.last[:describe]}: #{args.inspect}, #{o.inspect}"
50
+ end
51
+
52
+ t[:it] = if t[:it].strip[/:\z/]
53
+ "#{t[:it]} #{t[:input]}"
54
+ else
55
+ t[:it]
56
+ end
57
+
58
+ tests.last[:tests] << t
59
+ end
60
+
61
+ def stack arr
62
+ self << {it: args.shift, input: args.pop, stack: arr}
63
+ end
64
+
65
+ def raises o, m
66
+ self << {it: args.shift, input: args.pop, raises: [o, m]}
67
+ end
68
+
69
+ def output o
70
+ self << {it: args.shift, input: args.pop, output: o}
71
+ end
72
+
73
+ end # === class << self
74
+ end # == class It_Dsl
75
+
76
+ # =================================================
77
+ glob = ENV['RUBY_TEST_FILE'].to_s.strip.empty? ?
78
+ "specs/as_ruby/*.rb" :
79
+ ENV['RUBY_TEST_FILE']
80
+ # =================================================
81
+
82
+ Dir.glob(glob).sort.each { |f|
83
+
84
+ contents = File.read f
85
+ method_name = File.basename(f).gsub(/\A\d+-|\.rb\z/, '')
86
+
87
+ It_Dsl.describe method_name.to_sym
88
+ It_Dsl.instance_eval contents, f
89
+
90
+ } # === Dir.glob
91
+
92
+
93
+ It_Dsl.tests.each { |o|
94
+
95
+ describe o[:describe] do
96
+ o[:tests].each { |t|
97
+ it t[:it] do
98
+
99
+ case
100
+
101
+ when o[:describe] == :==
102
+ t[:input].should == t[:output]
103
+
104
+ when t.has_key?(:output)
105
+ Escape_Escape_Escape.send(o[:describe], t[:input])
106
+ .should == t[:output]
107
+
108
+ when !t.has_key?(:output) && t[:raises]
109
+ should.raise(t[:raises].first) {
110
+ Escape_Escape_Escape.send(o[:describe], t[:input])
111
+ }.message.should.match(t[:raises].last)
112
+
113
+ when t.has_key?(:stack) && t[:stack].is_a?(Array)
114
+
115
+ stack = t[:stack]
116
+ actual = Escape_Escape_Escape.send(o[:describe], t[:input])
117
+ target = stack.pop
4
118
 
5
- Dir.glob("specs/as_json/*.json").sort.each { |f|
6
- contents = MultiJson.load(File.read f)
7
- method_name = File.basename(f).gsub(/\A\d+-|\.json\Z/, '')
8
- describe ":#{method_name}" do
9
- contents.each { |t|
10
- it t["it"] do
11
- i = t["input"]
12
- o = t["output"]
13
- actual = Escape_Escape_Escape.send(method_name, i)
14
-
15
- case o
16
- when String
17
- actual.should == o
18
- when Array
19
- target = o.pop
20
119
  begin
21
- if o[1].is_a?(Array)
22
- meth = o.shift
23
- args = o.shift
120
+ case
121
+ when stack[1].is_a?(Array)
122
+ meth = stack.shift
123
+ args = stack.shift
24
124
  actual = actual.send(meth, *args)
125
+
126
+ when stack.first.is_a?(Symbol)
127
+ actual = actual.send(stack.shift)
128
+
25
129
  else
26
- fail "Unknown method: #{o[0].inspect}"
130
+ fail "Unknown method: #{stack[0].inspect}"
131
+
27
132
  end
28
- end while !o.empty?
133
+ end while !stack.empty?
29
134
 
30
135
  actual.should == target
136
+
137
+ else
138
+ fail "Unknown args for test: #{t.inspect}"
139
+
31
140
  end # === case
32
141
  end # === it
33
142
  }
34
143
  end
35
- }
144
+ } # === It_Dsl
145
+
146
+
147
+
@@ -0,0 +1 @@
1
+
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escape_escape_escape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sanitize
14
+ name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: 2.3.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: 2.3.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: escape_utils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: unf
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: htmlentities
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +150,20 @@ dependencies:
122
150
  - - ">="
123
151
  - !ruby/object:Gem::Version
124
152
  version: '1.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: sanitize
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 3.0.1
125
167
  description: "\n My way of escaping/encoding HTML with the proper entities.\n "
126
168
  email:
127
169
  - i-hate-spam-1234567@mailinator.com
@@ -132,22 +174,21 @@ files:
132
174
  - ".gitignore"
133
175
  - Gemfile
134
176
  - LICENSE
135
- - LICENSE.txt
136
177
  - README.md
137
178
  - VERSION
138
179
  - escape_escape_escape.gemspec
139
- - lib/beta.rb
140
- - lib/e_e_e.js
141
180
  - lib/escape_escape_escape.rb
142
- - package.json
143
- - specs/as_json/0001-html.json
144
- - specs/as_json/0002-inner_html.json
145
- - specs/as_json/0010-text.json
181
+ - specs/as_ruby/0001-html.rb
182
+ - specs/as_ruby/0002-decode_html.rb
183
+ - specs/as_ruby/0003-css_attr.rb
184
+ - specs/as_ruby/0003-css_selector.rb
185
+ - specs/as_ruby/0003-css_value.rb
186
+ - specs/as_ruby/0004-==.rb
187
+ - specs/as_ruby/0020-href.rb
188
+ - specs/as_ruby/0030-clean_utf8.rb
189
+ - specs/as_ruby/0040-escape.rb
146
190
  - specs/escape_escape_escape.rb
147
- - specs/helpers.rb
148
- - test/sanitize_attrs.js
149
- - test/sanitize_html.js
150
- - test/sanitize_un_escape.js
191
+ - specs/lib/helpers.rb
151
192
  homepage: https://github.com/da99/escape_escape_escape
152
193
  licenses:
153
194
  - MIT
@@ -168,11 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
209
  version: '0'
169
210
  requirements: []
170
211
  rubyforge_project:
171
- rubygems_version: 2.3.0
212
+ rubygems_version: 2.4.1
172
213
  signing_key:
173
214
  specification_version: 4
174
215
  summary: My way of escaping/encoding HTML.
175
- test_files:
176
- - test/sanitize_attrs.js
177
- - test/sanitize_html.js
178
- - test/sanitize_un_escape.js
216
+ test_files: []