str_sanitizer 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40adee975fa727815aab7c0c5342b29aa314141d
4
- data.tar.gz: 61bf3734eb9e0498d0340c336c906279b29accc6
3
+ metadata.gz: a7169e8b75393511b739ab251507841b7450a151
4
+ data.tar.gz: 3e7db2ddbfe1be726fd98595e7888ee9e90128b6
5
5
  SHA512:
6
- metadata.gz: 3ef826fb0f755c512fd636b6ba678041191517af6c6ba62f716ef17fe248022a8368ec38bf0339d06c055151930eebec476670adfd7161ccc590cbddc06f5832
7
- data.tar.gz: 07efaf0dac8247d325828b0711dd4f13e8d9310a42b4818a6470e4536ee8b6e1efb286cbdf7a715d68dd69e00cd8e61bdb8b2ddfdfc6142c90abeb9ed85dabc0
6
+ metadata.gz: 520ef5564f072087346b5efb995cbbdf0c3f8d0cff7032ddd723f3d0b6b0c5dd0b3354c156424c52f9e04b68e819b7a376f51fdc636a5d48ce50e6d42a59edb9
7
+ data.tar.gz: 91425bcd578d61ffeee7a11a2264df1c2f04294655c404abf97bea5bb07b5d380d2cde793ec53287706dce0db806d2813c2751ae5095ebbde81610dc7f68b54b
@@ -1,3 +1,8 @@
1
+ ## StrSanitizer 0.3.0 (August 21, 2017) ##
2
+
3
+ * Added a new `HtmlEntities` module which encodes and decodes HTML Entities.
4
+ * A new dependency named `htmlentities`.
5
+
1
6
  ## StrSanitizer 0.2.0 (August 09, 2017) ##
2
7
 
3
8
  * Changed the structure of the module in `lib/str_sanitizer/quotes.rb` file. Removed the `InstanceMethods` module and `included` class method of `Quotes` module. Remove the `ClassMethods` class too from `Quotes` module. Re-structured the whole module.
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in str_sanitizer.gemspec
6
6
  gemspec
7
+
8
+ gem 'htmlentities'
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/str_sanitizer.svg)](https://badge.fury.io/rb/str_sanitizer)
2
+ [![Build Status](https://travis-ci.org/JakariaBlaine/str_sanitizer.svg?branch=master)](https://travis-ci.org/JakariaBlaine/str_sanitizer)
2
3
  # StrSanitizer
3
4
 
4
5
  Welcome to this gem. This gem is about String Sanitization. This gem sanitizes the string which is given.
@@ -23,30 +24,44 @@ Or install it yourself as:
23
24
  ## Usage
24
25
 
25
26
  - To escape quotes of a string
26
- ```ruby
27
- require "str_sanitizer"
28
-
29
- hello = 'He said, "Hello!"'
30
- StrSanitizer.double_quote(hello) # => He said, \"Hello!\"
31
-
32
- hello = "She said, 'Hello!'"
33
- StrSanitizer.single_quote(hello) # => She said, \'Hello!\'
34
-
35
- both_quotes = "They said, \"Don't do it!\""
36
- StrSanitizer.both_quotes(both_quotes) # => They said, \"Don\'t do it!\"
37
- ```
38
- You can also check if the string has any quote or not
39
- ```ruby
40
- no_quote = "Hello, there."
41
- single_quote = "It's going down."
42
- double_quote = "He said, \"Hello\""
43
-
44
- StrSanitizer.has_any_quote?(no_quote) # => nil
45
- StrSanitizer.has_both_quotes?(no_quote) # => nil
46
-
47
- StrSanitizer.has_single_quotes?(single_quote) # => true
48
- StrSanitizer.has_double_quotes?(double_quote) # => true
49
- ```
27
+ ```ruby
28
+ require "str_sanitizer"
29
+
30
+ hello = 'He said, "Hello!"'
31
+ StrSanitizer.double_quote(hello) # => He said, \"Hello!\"
32
+
33
+ hello = "She said, 'Hello!'"
34
+ StrSanitizer.single_quote(hello) # => She said, \'Hello!\'
35
+
36
+ both_quotes = "They said, \"Don't do it!\""
37
+ StrSanitizer.both_quotes(both_quotes) # => They said, \"Don\'t do it!\"
38
+ ```
39
+ You can also check if the string has any quote or not
40
+ ```ruby
41
+ no_quote = "Hello, there."
42
+ single_quote = "It's going down."
43
+ double_quote = "He said, \"Hello\""
44
+
45
+ StrSanitizer.has_any_quote?(no_quote) # => nil
46
+ StrSanitizer.has_both_quotes?(no_quote) # => nil
47
+
48
+ StrSanitizer.has_single_quotes?(single_quote) # => true
49
+ StrSanitizer.has_double_quotes?(double_quote) # => true
50
+ ```
51
+
52
+ - To sanitize HTML Entities of a string
53
+ ```ruby
54
+ string = "<script>alert('Hola!!!')</script>"
55
+
56
+ StrSanitizer.html_encode(string) # => &lt;script&gt;alert('Hola!!!')&lt;script&gt;
57
+ ```
58
+ You can also decode the a string with encoded HTML entities
59
+ ```ruby
60
+ string = "&lt;script&gt;alert('Hola!!!')&lt;script&gt"
61
+
62
+ StrSanitizer.html_decode(string) # => <script>alert('Hola!!!')</script>
63
+ ```
64
+ Note: `htmlentities` was used for encoding and decoding process
50
65
 
51
66
  ## Development
52
67
 
@@ -22,7 +22,11 @@
22
22
 
23
23
  require "str_sanitizer/version"
24
24
  require "str_sanitizer/quotes"
25
+ require "str_sanitizer/html_entities"
25
26
 
27
+ # Author: Jakaria (mailto: jakariablaine120@gmail.com)
28
+ # Copyright: Copyright (c) 2017 Jakaria
26
29
  class StrSanitizer
27
30
  extend Quotes
31
+ extend HtmlEntities
28
32
  end
@@ -0,0 +1,46 @@
1
+ require 'htmlentities'
2
+
3
+ class StrSanitizer
4
+
5
+ # This modules encodes and decodes HTML Entities of a string
6
+ #
7
+ # Author: Jakaria (mailto: jakariablaine120@gmail.com)
8
+ # Copyright: Copyright (c) 2017 Jakaria
9
+ module HtmlEntities
10
+
11
+ # Instantiate htmlentities class to use it for encoding and decoding html entities
12
+ #
13
+ # Params:
14
+ # +none+
15
+ def initizalize
16
+ @coder = HTMLEntities.new
17
+ end
18
+
19
+ # Encodes the HTML entities of the given string
20
+ #
21
+ # Params:
22
+ # +str+:: A +string+ which needs to be escaped from html entities
23
+ # +options+:: Options for encoding. You can provide one or more than one option.
24
+ # If no option is given, :basic option will be used by default.
25
+ # Options available :basic, :named, :decimal, :hexadecimal
26
+ #
27
+ # Returns:
28
+ # +string+:: An HTML entities escaped +string+
29
+ def html_encode(string, *options)
30
+ @coder = HTMLEntities.new
31
+ @coder.encode(string, *options)
32
+ end
33
+
34
+ # Decodes the HTML entities of the given string
35
+ #
36
+ # Params:
37
+ # +str+:: A +string+ which needs to be decoded to html entities
38
+ #
39
+ # Returns:
40
+ # +string+:: A string with decoded HTML entities +string+
41
+ def html_decode(string)
42
+ @coder = HTMLEntities.new
43
+ @coder.decode(string)
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  class StrSanitizer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: str_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakaria Blaine
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - lib/str_sanitizer.rb
74
+ - lib/str_sanitizer/html_entities.rb
74
75
  - lib/str_sanitizer/quotes.rb
75
76
  - lib/str_sanitizer/version.rb
76
77
  - str_sanitizer.gemspec
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  version: '0'
95
96
  requirements: []
96
97
  rubyforge_project:
97
- rubygems_version: 2.5.1
98
+ rubygems_version: 2.5.2
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: This gem sanitizes the given string