jay 1.0.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.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/.gems +1 -0
  3. data/LICENSE +19 -0
  4. data/README.md +21 -0
  5. data/jay.gemspec +14 -0
  6. data/lib/jay.rb +19 -0
  7. data/test/jay.rb +28 -0
  8. metadata +64 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4743345e5e8970410282a2775714181bd1fc13e7
4
+ data.tar.gz: f414331310e0850ff631625e465b9803b4cff172
5
+ SHA512:
6
+ metadata.gz: 38d7d3bd72aa39d084af44abcf0cdf36b2bee136e53b36fa70f761623acdc399afbeceda2099208c7ab4e3faf3668618874b67d5c59c44da879f61df2d4238df
7
+ data.tar.gz: 014f38931789d39e40ae0a46ae34f504d9a1f871461aa241dd5e4c5468fff2187da4c83ab7bfe940cdf8767121da439be3fb681bf44db374f24b501c681e8ec3
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
+ jay
2
+ ===
3
+
4
+ JavaScript escaping.
5
+
6
+ Usage
7
+ -----
8
+
9
+ ```ruby
10
+ require "jay"
11
+
12
+ Jay.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 jay
21
+ ```
data/jay.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "jay"
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/jay"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_development_dependency "cutest"
14
+ end
data/lib/jay.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Jay
2
+ JS_ESCAPE = {
3
+ '\\' => '\\\\',
4
+ '</' => '<\/',
5
+ "\r\n" => '\n',
6
+ "\n" => '\n',
7
+ "\r" => '\n',
8
+ '"' => '\\"',
9
+ "'" => "\\'",
10
+ "\u2028" => "&#x2028;",
11
+ "\u2029" => "&#x2029;"
12
+ }
13
+
14
+ UNSAFE = /(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u
15
+
16
+ def self.j(s)
17
+ s.to_str.gsub(UNSAFE, JS_ESCAPE)
18
+ end
19
+ end
data/test/jay.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "cutest"
2
+ require_relative "../lib/jay"
3
+
4
+ test "safe string" do
5
+ assert_equal "hola", Jay.j("hola")
6
+ end
7
+
8
+ test "escapes quotes" do
9
+ assert_equal %(\\'s\\' \\"d\\"), Jay.j(%('s' "d"))
10
+ end
11
+
12
+ test "escapes newlines" do
13
+ assert_equal %(\\n \\n), Jay.j(%(\n \r\n))
14
+ end
15
+
16
+ test "escapes backslashes" do
17
+ assert_equal %(\\\\), Jay.j(%(\\))
18
+ end
19
+
20
+ test "escapes closed html tags" do
21
+ assert_equal %(<open> not <\\/closed>), Jay.j(%(<open> not </closed>))
22
+ end
23
+
24
+ # http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
25
+ test "escapes \u2028 and \u2029 characters" do
26
+ assert_equal "unicode &#x2028;", Jay.j("unicode \342\200\250")
27
+ assert_equal "unicode &#x2029;", Jay.j("unicode \342\200\251")
28
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jay
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-10-30 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
+ - jay.gemspec
38
+ - lib/jay.rb
39
+ - test/jay.rb
40
+ homepage: https://github.com/frodsan/jay
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.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: JavaScript escaping.
64
+ test_files: []