jodd 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +1 -0
- data/LICENSE +19 -0
- data/README.md +21 -0
- data/jodd.gemspec +14 -0
- data/lib/jodd.rb +17 -0
- data/test/jodd.rb +22 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b1fbf7c4910fc6d983dba0a007c9da01f72b9f1
|
4
|
+
data.tar.gz: 28c4a78501d458c93e0b54992c51f02780ad2231
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39bbbca851b6c7886a2240f20a327fe89a48f535bcbbdadb91e6110646424825425cd98556da87c3b353e55aa7535113692bf0a8cf8b96c17a0fb8bfd497333b
|
7
|
+
data.tar.gz: 8f9122c19574b44d8f5680caa620e2b1422c4d49b4f6ec02cf7b5484a595a5194af1786e4e58243221f8b0e0c58a56ac5d81a5501dd01d2c8fc05ee0dd039912
|
data/.gems
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cutest -v 1.2.1
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Francesco Rodríguez
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
jodd
|
2
|
+
====
|
3
|
+
|
4
|
+
JavaScript escaping.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "jodd"
|
11
|
+
|
12
|
+
Jodd.j(%(back \\ not </closed> 'newline \n return \r "both \r\n))
|
13
|
+
# => "back \\\\ not <\\/closed> \\'newline \\n return \\n \\\"both \\n"
|
14
|
+
```
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ gem install jodd
|
21
|
+
```
|
data/jodd.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "jodd"
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.summary = "JavaScript escaping."
|
5
|
+
s.description = "Escapes carriage returns, and single and double quotes."
|
6
|
+
s.authors = ["Francesco Rodríguez"]
|
7
|
+
s.email = ["frodsan@me.com"]
|
8
|
+
s.homepage = "https://github.com/frodsan/jodd"
|
9
|
+
s.license = "MIT"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
|
13
|
+
s.add_development_dependency "cutest"
|
14
|
+
end
|
data/lib/jodd.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Jodd
|
2
|
+
JS_ESCAPE = {
|
3
|
+
'\\' => '\\\\',
|
4
|
+
'</' => '<\/',
|
5
|
+
"\r\n" => '\n',
|
6
|
+
"\n" => '\n',
|
7
|
+
"\r" => '\n',
|
8
|
+
'"' => '\\"',
|
9
|
+
"'" => "\\'",
|
10
|
+
}
|
11
|
+
|
12
|
+
UNSAFE = /(\\|<\/|\r\n|[\n\r"'])/u
|
13
|
+
|
14
|
+
def self.j(s)
|
15
|
+
s.to_str.gsub(UNSAFE, JS_ESCAPE)
|
16
|
+
end
|
17
|
+
end
|
data/test/jodd.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "cutest"
|
2
|
+
require_relative "../lib/jodd"
|
3
|
+
|
4
|
+
test "safe string" do
|
5
|
+
assert_equal "hola", Jodd.j("hola")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "escapes quotes" do
|
9
|
+
assert_equal %(\\'s\\' \\"d\\"), Jodd.j(%('s' "d"))
|
10
|
+
end
|
11
|
+
|
12
|
+
test "escapes newlines" do
|
13
|
+
assert_equal %(\\n \\n), Jodd.j(%(\n \r\n))
|
14
|
+
end
|
15
|
+
|
16
|
+
test "escapes backslashes" do
|
17
|
+
assert_equal %(\\\\), Jodd.j(%(\\))
|
18
|
+
end
|
19
|
+
|
20
|
+
test "escapes closed html tags" do
|
21
|
+
assert_equal %(<open> not <\\/closed>), Jodd.j(%(<open> not </closed>))
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jodd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Rodríguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cutest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Escapes carriage returns, and single and double quotes.
|
28
|
+
email:
|
29
|
+
- frodsan@me.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gems
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- jodd.gemspec
|
38
|
+
- lib/jodd.rb
|
39
|
+
- test/jodd.rb
|
40
|
+
homepage: https://github.com/frodsan/jodd
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.0.14
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: JavaScript escaping.
|
64
|
+
test_files: []
|