erubi 1.5.0 → 1.6.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 +4 -4
- data/CHANGELOG +4 -0
- data/README.rdoc +2 -2
- data/lib/erubi.rb +22 -9
- data/test/test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7624aff12923d9d250f5d3ba715638577669ad17
|
4
|
+
data.tar.gz: ee918f650866fb2652d79a24a6d67f93673cb973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6b7e14a72e167dba29bbed06fa243cc21d3e0c4dfe6d3a6f42a0f4faf42bdc790cd6ae93aa18921ff0d69dbc575c2958d6d7319606eed25e5becb87d2b01dc0
|
7
|
+
data.tar.gz: 82b8d817f9da8862b4f7823e250f9f527d503da254650c3ade12ba24c17dea70ee04c3be7cb30cc7d0fba301eda8c9e6047ba46c7a2f6aa293f3d6512a6219a0
|
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -8,8 +8,8 @@ the same basic algorithm, with the following differences:
|
|
8
8
|
* Works with ruby's --enable-frozen-string-literal option
|
9
9
|
* Automatically freezes strings for template text when ruby optimizes it (on ruby 2.1+)
|
10
10
|
* Escapes ' (apostrophe) when escaping for better XSS protection
|
11
|
-
* Has
|
12
|
-
* Has
|
11
|
+
* Has 6x faster escaping on ruby 2.3+ by using cgi/escape
|
12
|
+
* Has 86% smaller memory footprint
|
13
13
|
* Does no monkey patching (Erubis adds a method to Kernel)
|
14
14
|
* Uses an immutable design (all options passed to the constructor, which returns a frozen object)
|
15
15
|
* Has simpler internals (1 file, <150 lines of code)
|
data/lib/erubi.rb
CHANGED
@@ -1,29 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Erubi
|
4
|
-
|
4
|
+
VERSION = '1.6.0'
|
5
5
|
RANGE_ALL = 0..-1
|
6
6
|
|
7
7
|
if RUBY_VERSION >= '1.9'
|
8
8
|
RANGE_FIRST = 0
|
9
9
|
RANGE_LAST = -1
|
10
10
|
TEXT_END = RUBY_VERSION >= '2.1' ? "'.freeze;" : "';"
|
11
|
-
|
12
|
-
# Escape the following characters with their HTML/XML
|
13
|
-
# equivalents.
|
14
|
-
def self.h(value)
|
15
|
-
value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)
|
16
|
-
end
|
17
11
|
else
|
18
12
|
# :nocov:
|
19
13
|
RANGE_FIRST = 0..0
|
20
14
|
RANGE_LAST = -1..-1
|
21
15
|
TEXT_END = "';"
|
16
|
+
end
|
22
17
|
|
18
|
+
begin
|
19
|
+
require 'cgi/escape'
|
20
|
+
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
|
21
|
+
CGI = Object.new
|
22
|
+
CGI.extend(::CGI::Util)
|
23
|
+
end
|
23
24
|
def self.h(value)
|
24
|
-
value.to_s
|
25
|
+
CGI.escapeHTML(value.to_s)
|
26
|
+
end
|
27
|
+
rescue LoadError
|
28
|
+
ESCAPE_TABLE = {'&' => '&'.freeze, '<' => '<'.freeze, '>' => '>'.freeze, '"' => '"'.freeze, "'" => '''.freeze}.freeze
|
29
|
+
if RUBY_VERSION >= '1.9'
|
30
|
+
# Escape the following characters with their HTML/XML
|
31
|
+
# equivalents.
|
32
|
+
def self.h(value)
|
33
|
+
value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
def self.h(value)
|
37
|
+
value.to_s.gsub(/[&<>"']/){|s| ESCAPE_TABLE[s]}
|
38
|
+
end
|
25
39
|
end
|
26
|
-
# :nocov:
|
27
40
|
end
|
28
41
|
|
29
42
|
class Engine
|
data/test/test.rb
CHANGED
@@ -101,7 +101,7 @@ END2
|
|
101
101
|
<tbody>
|
102
102
|
<tr>
|
103
103
|
<td>1</td>
|
104
|
-
<td>&&#
|
104
|
+
<td>&'<>"2</td>
|
105
105
|
</tr>
|
106
106
|
</tbody>
|
107
107
|
</table>
|
@@ -150,7 +150,7 @@ END2
|
|
150
150
|
<tbody>
|
151
151
|
<tr>
|
152
152
|
<td>1</td>
|
153
|
-
<td>&&#
|
153
|
+
<td>&'<>"2</td>
|
154
154
|
</tr>
|
155
155
|
</tbody>
|
156
156
|
</table>
|
@@ -472,7 +472,7 @@ END2
|
|
472
472
|
<tbody>
|
473
473
|
<tr>
|
474
474
|
<td>1</td>
|
475
|
-
<td>&&#
|
475
|
+
<td>&'<>"2</td>
|
476
476
|
</tr>
|
477
477
|
</tbody>
|
478
478
|
</table>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erubi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|