sinarey_support 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinarey_support/core_ext/string/output_safety.rb +11 -29
- data/sinarey_support.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee72ba2d2528255744df5fefedc614f0158970d0
|
4
|
+
data.tar.gz: 87f4cd9e9db9ed77ee81b8ed9bf002d7726d94f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3384fd18fbe63b0e35fbd176c1e79e691bd3b82e17af9515a981b1e2c65cf2eb7bf9cf6617028cbde5ec2e86989f534dd02c9f47047823de12aaae5bbe7fd36c
|
7
|
+
data.tar.gz: 07fbfea17a38647618fb5349ee8caa2ba9316a79509483f337c80dc77a19ec2363302d312fe1cf52591256fe6d2032ed457e8f9a44e9e99314322305c4a78975
|
@@ -3,49 +3,31 @@ require 'sinarey_support/core_ext/kernel/singleton_class'
|
|
3
3
|
|
4
4
|
class ERB
|
5
5
|
module Util
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
# html_escape_once('1 < 2 & 3')
|
14
|
-
# # => "1 < 2 & 3"
|
15
|
-
#
|
16
|
-
# html_escape_once('<< Accept & Checkout')
|
17
|
-
# # => "<< Accept & Checkout"
|
6
|
+
|
7
|
+
HTML_ECP = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' }
|
8
|
+
JSON_ECP = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
|
9
|
+
HTML_ECP_ONCE = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
10
|
+
JSON_ECP_REGEXP = /[&"><]/
|
11
|
+
|
18
12
|
def html_escape_once(s)
|
19
|
-
result = s.to_s.gsub(
|
13
|
+
result = s.to_s.gsub(HTML_ECP_ONCE, HTML_ECP)
|
20
14
|
s.html_safe? ? result.html_safe : result
|
21
15
|
end
|
22
16
|
|
23
17
|
module_function :html_escape_once
|
24
18
|
|
25
|
-
# A utility method for escaping HTML entities in JSON strings
|
26
|
-
# using \uXXXX JavaScript escape sequences for string literals:
|
27
|
-
#
|
28
|
-
# json_escape('is a > 0 & a < 10?')
|
29
|
-
# # => is a \u003E 0 \u0026 a \u003C 10?
|
30
|
-
#
|
31
|
-
# Note that after this operation is performed the output is not
|
32
|
-
# valid JSON. In particular double quotes are removed:
|
33
|
-
#
|
34
|
-
# json_escape('{"name":"john","created_at":"2010-04-28T01:39:31Z","id":1}')
|
35
|
-
# # => {name:john,created_at:2010-04-28T01:39:31Z,id:1}
|
36
19
|
def json_escape(s)
|
37
|
-
result = s.to_s.gsub(
|
20
|
+
result = s.to_s.gsub(JSON_ECP_REGEXP, JSON_ECP)
|
38
21
|
s.html_safe? ? result.html_safe : result
|
39
22
|
end
|
40
23
|
|
41
24
|
module_function :json_escape
|
42
25
|
|
43
|
-
|
44
26
|
def sinarey_escape(value)
|
45
27
|
if value.html_safe?
|
46
28
|
value.to_s
|
47
29
|
else
|
48
|
-
value.to_s.gsub(/[&"'><]/,
|
30
|
+
value.to_s.gsub(/[&"'><]/, HTML_ECP)
|
49
31
|
end
|
50
32
|
end
|
51
33
|
|
@@ -84,7 +66,7 @@ class NilClass
|
|
84
66
|
end
|
85
67
|
end
|
86
68
|
|
87
|
-
module
|
69
|
+
module SinareySupport #:nodoc:
|
88
70
|
class SafeBuffer < String
|
89
71
|
UNSAFE_STRING_METHODS = %w(
|
90
72
|
capitalize chomp chop delete downcase gsub lstrip next reverse rstrip
|
@@ -193,6 +175,6 @@ end
|
|
193
175
|
|
194
176
|
class String
|
195
177
|
def html_safe
|
196
|
-
|
178
|
+
SinareySupport::SafeBuffer.new(self)
|
197
179
|
end
|
198
180
|
end
|
data/sinarey_support.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinarey_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: some useful methods for sinatra framework
|
14
14
|
email:
|
@@ -60,12 +60,12 @@ require_paths:
|
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - '>='
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|