sanistring 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +7 -1
- data/lib/sanistring.rb +0 -1
- data/lib/sanistring/sanitize.rb +2 -2
- data/lib/sanistring/version.rb +1 -1
- data/spec/sanitizer_spec.rb +5 -5
- metadata +1 -2
- data/lib/sanistring/list.rb +0 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzY3OWRmYTc0ZWEwMWRlZjczMjYxZDg1MWVkNzhhMmRiMDc0YjJkYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2U4MWJlODA2ODE4NmZlYzk2ZjVhODBiNTZjMjlkNDNhZTEzYTkzYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODM5MGYxMzExN2Q3OGY4NmMxNTc1YjMxNTU0YjA3ZjYzNTc2YTQ0M2MyNjZh
|
10
|
+
Y2Q4Njg0ODFjNzM4NmQ1YmYyYTJjNzUyYjQ4NjhkNGRlZTQwZGE2NTJlYTRk
|
11
|
+
OTU2NGZiNTA0OTIyMmNmNGFiOGJhMDA4YTA3YjkyNjhlMTE1MzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGFiOTBlZjJjNTI4OTllNDcxZGEyNzNhNmQxNDU5MDIwMzMxMzk3OWI0Y2M3
|
14
|
+
YmVkYzU2ZDc5NjMwMzYyZjJmMjFkNWU2YjRlNzZlMDRiMWU3ZTJjNDhhYjdj
|
15
|
+
M2VhMTA1ZWY5M2Q3MmEyMzQxMmQ0YzY0OWQ3YmE3ZGNkOWQzMjY=
|
data/README.md
CHANGED
@@ -19,7 +19,13 @@ Or install it yourself as:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
|
22
|
+
|
23
|
+
# alphanumeric
|
24
|
+
Sanistring.sanitize('../path/to/some/file', whitelist: :alphanumeric)
|
25
|
+
|
26
|
+
# custom whitelist
|
27
|
+
Sanistring.sanitize('../path/to/some/file', whitelist: '+-*/=')
|
28
|
+
|
23
29
|
```
|
24
30
|
|
25
31
|
## Contributing
|
data/lib/sanistring.rb
CHANGED
data/lib/sanistring/sanitize.rb
CHANGED
@@ -4,9 +4,9 @@ module Sanistring
|
|
4
4
|
sanitized = name.split('').map{ |char|
|
5
5
|
if opts[:replace] && opts[:replace][char]
|
6
6
|
opts[:replace][char]
|
7
|
-
elsif opts[:whitelist].is_a?(
|
7
|
+
elsif opts[:whitelist].is_a?(Symbol)
|
8
8
|
case opts[:whitelist]
|
9
|
-
when
|
9
|
+
when :alpha_numeric, :alphanumeric
|
10
10
|
char if !!(/[a-zA-Z0-9]/ =~ char)
|
11
11
|
else
|
12
12
|
nil
|
data/lib/sanistring/version.rb
CHANGED
data/spec/sanitizer_spec.rb
CHANGED
@@ -4,23 +4,23 @@ describe Sanistring do
|
|
4
4
|
|
5
5
|
describe '#sanitize' do
|
6
6
|
it 'removes prohibited characters' do
|
7
|
-
Sanistring.sanitize('../abc', whitelist:
|
7
|
+
Sanistring.sanitize('../abc', whitelist: :alphanumeric).should == 'abc'
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'replaces characters' do
|
11
|
-
Sanistring.sanitize(' adam ', whitelist:
|
11
|
+
Sanistring.sanitize(' adam ', whitelist: :alphanumeric, replace: {' '=> ''}).should == 'adam'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'returns empty string when string is entirely prohibited characters' do
|
15
|
-
Sanistring.sanitize('..', whitelist:
|
15
|
+
Sanistring.sanitize('..', whitelist: :alphanumeric).should == ''
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'upcases string' do
|
19
|
-
Sanistring.sanitize('abc', upcase: true, whitelist:
|
19
|
+
Sanistring.sanitize('abc', upcase: true, whitelist: :alphanumeric).should == 'ABC'
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'downcases string' do
|
23
|
-
Sanistring.sanitize('ABC', downcase: true, whitelist:
|
23
|
+
Sanistring.sanitize('ABC', downcase: true, whitelist: :alphanumeric).should == 'abc'
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanistring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hallett
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
68
|
- lib/sanistring.rb
|
69
|
-
- lib/sanistring/list.rb
|
70
69
|
- lib/sanistring/sanitize.rb
|
71
70
|
- lib/sanistring/version.rb
|
72
71
|
- sanistring.gemspec
|