escape_utils 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d7424e692690ecb13b6eb5ee969a532bd1fe505a
4
- data.tar.gz: 5dcef4bb75091869f767949c6f3f93e97facfe03
2
+ SHA256:
3
+ metadata.gz: 6f26c8a24ba01ecb130e04ef9af6802ab2deb56455527ccd551ae93839736604
4
+ data.tar.gz: 4fc6f51b66cd0c773cf3aea923023ccb66e31cd865e9b89da81a9119540cae05
5
5
  SHA512:
6
- metadata.gz: 64563f3e25b7525fac604004e6749ae05a96a156fa0dbac031b6b3dd6337833f9c4ede0a92c0d8952fa774dcfd94e87648b52b8b888a3c3730c9ecb64864922f
7
- data.tar.gz: a96b091153d336cc744c445a6ff96d0ed99244e15f9628d44c492dcf393b39040404944bba55eda02badf2ab53c75b351212159c562d7ad99c08cd6652651613
6
+ metadata.gz: f0f6556bd83c1068189d5a3183b2ad1df88bd4a79f46f119ae7fcfdff4339544d6e1654379fe0b64cd6f07865c67eafa83b9caa236e0ac6b23de1814fd808b2e
7
+ data.tar.gz: dd5e1b3baf9c594d48f0580f6c71c766e7e341fce332dba8fbd7f0a36d8611bb70e043ef3808c95e9d6a774a71d088e1136ff8025c2ae43e1588f0500d8d04ad
@@ -0,0 +1,43 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ rubies:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [ ruby-head, '3.1', '3.0', '2.7', '2.6', '2.5' ]
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Run test
22
+ run: rake
23
+ - name: Install gem
24
+ run: rake install
25
+ platforms:
26
+ strategy:
27
+ matrix:
28
+ os: [macos, windows]
29
+ ruby: ['2.5']
30
+ runs-on: ${{ matrix.os }}-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v3
34
+ - name: Set up Ruby
35
+ uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+ - name: Install dependencies
39
+ run: bundle install
40
+ - name: Run test
41
+ run: bundle exec rake
42
+ - name: Install gem
43
+ run: bundle exec rake install
data/.gitignore CHANGED
@@ -7,4 +7,3 @@ doc/*
7
7
  tmp/
8
8
  Gemfile.lock
9
9
  vendor/*
10
- bin/
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Unreleased
2
+
3
+ # 1.2.2
4
+
5
+ - Update EscapeUtils.escape_javascript to match Rails `escape_javascript`
6
+ Now escapes, Backquotes (```), Dollar (`$`), `U+2000` and `U+2001`
7
+ - Make the Rack monkey patch a noop as it's no longer correct since circa 2011.
8
+ - Require Ruby 2.5+
9
+ - Stop escaping `~` like `CGI.escape` does since Ruby 2.5
10
+
11
+ # 1.2.1
12
+
13
+ - Historical version
data/Gemfile CHANGED
@@ -1,3 +1,18 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test do
4
+ gem 'rake-compiler'
5
+ gem 'minitest'
6
+ gem 'actionview'
7
+ end
8
+
9
+ group :benchmark do
10
+ gem 'benchmark-ips'
11
+ gem 'rack'
12
+ gem 'haml'
13
+ gem 'fast_xs'
14
+ gem 'actionpack'
15
+ gem 'url_escape'
16
+ end
17
+
3
18
  gemspec
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Being as though we're all html escaping everything these days, why not make it faster?
4
4
 
5
- For character encoding in 1.9, the output string's encoding is copied from the input string.
5
+ For character encoding, the output string's encoding is copied from the input string.
6
6
 
7
7
  It has monkey-patches for Rack::Utils, CGI, URI, ERB::Util and Haml and ActionView so you can drop this in and have your app start escaping fast as balls in no time
8
8
 
@@ -10,7 +10,7 @@ It supports HTML, URL, URI and Javascript escaping/unescaping.
10
10
 
11
11
  ## Installing
12
12
 
13
- Compatible with Ruby 1.9.3+
13
+ Compatible with Ruby 2.5+
14
14
 
15
15
  ``` sh
16
16
  gem install escape_utils
@@ -52,7 +52,6 @@ html = EscapeUtils.unescape_html(escaped_html)
52
52
  #### Monkey Patches
53
53
 
54
54
  ``` ruby
55
- require 'escape_utils/html/rack' # to patch Rack::Utils
56
55
  require 'escape_utils/html/erb' # to patch ERB::Util
57
56
  require 'escape_utils/html/cgi' # to patch CGI
58
57
  require 'escape_utils/html/haml' # to patch Haml::Helpers
@@ -84,7 +83,6 @@ EscapeUtils.unescape_url(escaped_url) == url # => true
84
83
  ``` ruby
85
84
  require 'escape_utils/url/cgi' # to patch CGI
86
85
  require 'escape_utils/url/erb' # to patch ERB::Util
87
- require 'escape_utils/url/rack' # to patch Rack::Utils
88
86
  require 'escape_utils/url/uri' # to patch URI
89
87
  ```
90
88
 
data/Rakefile CHANGED
@@ -1,12 +1,14 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rake/testtask'
2
3
 
3
4
  Rake::TestTask.new do |t|
4
- t.pattern = "test/**/*_test.rb"
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
5
8
  end
6
9
 
7
10
  task :default => :test
8
11
 
9
- gem 'rake-compiler', '>= 0.7.5'
10
12
  require "rake/extensiontask"
11
13
 
12
14
  Rake::ExtensionTask.new('escape_utils') do |ext|
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "escape_utils"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/escape_utils.gemspec CHANGED
@@ -16,16 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.description = %q{Quickly perform HTML, URL, URI and Javascript escaping/unescaping}
17
17
  s.test_files = `git ls-files test`.split("\n")
18
18
 
19
- s.required_ruby_version = ">= 1.9.3"
20
-
21
- # tests
22
- s.add_development_dependency 'rake-compiler', ">= 0.7.5"
23
- s.add_development_dependency 'minitest', ">= 5.0.0"
24
- # benchmarks
25
- s.add_development_dependency 'benchmark-ips'
26
- s.add_development_dependency 'rack'
27
- s.add_development_dependency 'haml'
28
- s.add_development_dependency 'fast_xs'
29
- s.add_development_dependency 'actionpack'
30
- s.add_development_dependency 'url_escape'
19
+ s.required_ruby_version = ">= 2.5"
31
20
  end
@@ -167,7 +167,7 @@ static VALUE rb_eu_escape_xml(VALUE self, VALUE str)
167
167
  */
168
168
  static VALUE rb_eu_escape_js(VALUE self, VALUE str)
169
169
  {
170
- return rb_eu__generic(str, &houdini_escape_js);
170
+ return rb_eu__generic(rb_obj_as_string(str), &houdini_escape_js);
171
171
  }
172
172
 
173
173
  static VALUE rb_eu_unescape_js(VALUE self, VALUE str)
@@ -7,10 +7,11 @@
7
7
  static const char JS_ESCAPE[] = {
8
8
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
9
9
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10
- 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
10
+ 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
11
11
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
12
12
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13
13
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
14
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14
15
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15
16
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16
17
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -18,8 +19,7 @@ static const char JS_ESCAPE[] = {
18
19
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19
20
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20
21
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23
23
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24
24
  };
25
25
 
@@ -51,6 +51,18 @@ houdini_escape_js(gh_buf *ob, const uint8_t *src, size_t size)
51
51
  ch = src[i];
52
52
 
53
53
  switch (ch) {
54
+ case 226:
55
+ if (i + 2 < size && src[i + 1] == 128) {
56
+ if (src[i + 2] == 168) {
57
+ gh_buf_put(ob, "&#x2028;", 8);
58
+ i += 2;
59
+ } else if (src[i + 2] == 169) {
60
+ gh_buf_put(ob, "&#x2029;", 8);
61
+ i += 2;
62
+ }
63
+ }
64
+ break;
65
+
54
66
  case '/':
55
67
  /*
56
68
  * Escape only if preceded by a lt
@@ -12,7 +12,7 @@ static const char URL_SAFE[] = {
12
12
  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
13
13
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
14
14
  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
15
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
15
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
16
16
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17
17
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18
18
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1,12 +0,0 @@
1
- module Rack
2
- module Utils
3
- def escape(url)
4
- EscapeUtils.escape_url(url.to_s)
5
- end
6
- def unescape(url)
7
- EscapeUtils.unescape_url(url.to_s)
8
- end
9
- module_function :escape
10
- module_function :unescape
11
- end
12
- end
@@ -1,3 +1,3 @@
1
1
  module EscapeUtils
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  module Builder
2
- class XmlBase < BlankSlate
2
+ class XmlBase
3
3
  private
4
4
  def _escape(text)
5
- EscapeUtils.escape_xml(text.to_s)
5
+ ::EscapeUtils.escape_xml(text.to_s)
6
6
  end
7
7
  end
8
8
  end
@@ -105,26 +105,24 @@ class HtmlEscapeTest < Minitest::Test
105
105
  end
106
106
  end
107
107
 
108
- if RUBY_VERSION =~ /^1.9/
109
- def test_utf8_or_ascii_input_only
110
- str = "<b>Bourbon & Branch</b>"
111
-
112
- str.force_encoding 'ISO-8859-1'
113
- assert_raises Encoding::CompatibilityError do
114
- EscapeUtils.escape_html(str)
115
- end
116
-
117
- str.force_encoding 'UTF-8'
118
- begin
119
- EscapeUtils.escape_html(str)
120
- rescue Encoding::CompatibilityError => e
121
- assert_nil e, "#{e.class.name} raised, expected not to"
122
- end
108
+ def test_utf8_or_ascii_input_only
109
+ str = "<b>Bourbon & Branch</b>"
110
+
111
+ str.force_encoding 'ISO-8859-1'
112
+ assert_raises Encoding::CompatibilityError do
113
+ EscapeUtils.escape_html(str)
123
114
  end
124
115
 
125
- def test_return_value_is_tagged_as_utf8
126
- str = "<b>Bourbon & Branch</b>".encode('utf-8')
127
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_html(str).encoding
116
+ str.force_encoding 'UTF-8'
117
+ begin
118
+ EscapeUtils.escape_html(str)
119
+ rescue Encoding::CompatibilityError => e
120
+ assert_nil e, "#{e.class.name} raised, expected not to"
128
121
  end
129
122
  end
123
+
124
+ def test_return_value_is_tagged_as_utf8
125
+ str = "<b>Bourbon & Branch</b>".encode('utf-8')
126
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_html(str).encoding
127
+ end
130
128
  end
@@ -23,26 +23,24 @@ class HtmlUnescapeTest < Minitest::Test
23
23
  assert_equal "&lt", EscapeUtils.unescape_html("&lt")
24
24
  end
25
25
 
26
- if RUBY_VERSION =~ /^1.9/
27
- def test_input_must_be_utf8_or_ascii
28
- escaped = EscapeUtils.escape_html("<b>Bourbon & Branch</b>")
29
-
30
- escaped.force_encoding 'ISO-8859-1'
31
- assert_raises Encoding::CompatibilityError do
32
- EscapeUtils.unescape_html(escaped)
33
- end
34
-
35
- escaped.force_encoding 'UTF-8'
36
- begin
37
- EscapeUtils.unescape_html(escaped)
38
- rescue Encoding::CompatibilityError => e
39
- assert_nil e, "#{e.class.name} raised, expected not to"
40
- end
26
+ def test_input_must_be_utf8_or_ascii
27
+ escaped = EscapeUtils.escape_html("<b>Bourbon & Branch</b>")
28
+
29
+ escaped.force_encoding 'ISO-8859-1'
30
+ assert_raises Encoding::CompatibilityError do
31
+ EscapeUtils.unescape_html(escaped)
41
32
  end
42
33
 
43
- def test_return_value_is_tagged_as_utf8
44
- escaped = EscapeUtils.escape_html("<b>Bourbon & Branch</b>")
45
- assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_html(escaped).encoding
34
+ escaped.force_encoding 'UTF-8'
35
+ begin
36
+ EscapeUtils.unescape_html(escaped)
37
+ rescue Encoding::CompatibilityError => e
38
+ assert_nil e, "#{e.class.name} raised, expected not to"
46
39
  end
47
40
  end
41
+
42
+ def test_return_value_is_tagged_as_utf8
43
+ escaped = EscapeUtils.escape_html("<b>Bourbon & Branch</b>")
44
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_html(escaped).encoding
45
+ end
48
46
  end
@@ -1,42 +1,80 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
+ require 'active_support'
4
+ require 'active_support/json'
5
+ require 'action_view'
6
+ require 'action_view/helpers'
7
+
3
8
  class JavascriptEscapeTest < Minitest::Test
9
+ ActiveSupport.escape_html_entities_in_json = true
10
+
11
+ module ActionViewHelper
12
+ include ActionView::Helpers::JavaScriptHelper
13
+ extend self
14
+ end
15
+
4
16
  def test_returns_empty_string_if_nil_passed
5
- assert_equal "", EscapeUtils.escape_javascript(nil)
17
+ assert_compatible nil
6
18
  end
7
19
 
8
20
  def test_quotes_and_newlines
9
- assert_equal %(This \\"thing\\" is really\\n netos\\n\\n\\'), EscapeUtils.escape_javascript(%(This "thing" is really\n netos\r\n\n'))
21
+ assert_compatible %(This "thing" is really\n netos\r\n\n')
10
22
  end
11
23
 
12
24
  def test_backslashes
13
- assert_equal %(backslash\\\\test), EscapeUtils.escape_javascript(%(backslash\\test))
25
+ assert_compatible %(backslash\\test)
14
26
  end
15
27
 
16
28
  def test_closed_html_tags
17
- assert_equal %(keep <open>, but dont <\\/close> tags), EscapeUtils.escape_javascript(%(keep <open>, but dont </close> tags))
29
+ assert_compatible %(keep <open>, but dont </close> tags)
30
+ end
31
+
32
+ def test_escape_javascript
33
+ assert_compatible 123
34
+ assert_compatible :en
35
+ assert_compatible false
36
+ assert_compatible true
37
+ assert_compatible %(don't </close> tags)
38
+ assert_compatible (+%(unicode \342\200\250 newline)).force_encoding(Encoding::UTF_8).encode!
39
+ assert_compatible (+%(unicode \342\200\251 newline)).force_encoding(Encoding::UTF_8).encode!
40
+ assert_compatible %(don't </close> tags)
41
+ end
42
+
43
+ def test_escape_backtick
44
+ assert_compatible "`"
18
45
  end
19
46
 
20
- if RUBY_VERSION =~ /^1.9/
21
- def test_input_must_be_utf8_or_ascii
22
- str = "dont </close> tags"
47
+ def test_escape_dollar_sign
48
+ assert_compatible "$"
49
+ end
23
50
 
24
- str.force_encoding 'ISO-8859-1'
25
- assert_raises Encoding::CompatibilityError do
26
- EscapeUtils.escape_javascript(str)
27
- end
51
+ def test_input_must_be_utf8_or_ascii
52
+ str = "dont </close> tags"
28
53
 
29
- str.force_encoding 'UTF-8'
30
- begin
31
- EscapeUtils.escape_javascript(str)
32
- rescue Encoding::CompatibilityError => e
33
- assert_nil e, "#{e.class.name} raised, expected not to"
34
- end
54
+ str.force_encoding Encoding::ISO_8859_1
55
+ assert_raises Encoding::CompatibilityError do
56
+ EscapeUtils.escape_javascript(str)
35
57
  end
36
58
 
37
- def test_return_value_is_tagged_as_utf8
38
- str = "dont </close> tags"
39
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_javascript(str).encoding
59
+ str.force_encoding Encoding::UTF_8
60
+ begin
61
+ EscapeUtils.escape_javascript(str)
62
+ rescue Encoding::CompatibilityError => e
63
+ assert_nil e, "#{e.class.name} raised, expected not to"
40
64
  end
41
65
  end
66
+
67
+ def test_return_value_is_tagged_as_utf8
68
+ str = "dont </close> tags"
69
+ assert_equal Encoding::UTF_8, EscapeUtils.escape_javascript(str).encoding
70
+ end
71
+
72
+ private
73
+
74
+ def assert_compatible(src)
75
+ assert_equal(
76
+ ActionViewHelper.escape_javascript(src),
77
+ EscapeUtils.escape_javascript(src),
78
+ )
79
+ end
42
80
  end
@@ -21,26 +21,24 @@ class JavascriptUnescapeTest < Minitest::Test
21
21
  assert_equal "\\", EscapeUtils.unescape_javascript("\\")
22
22
  end
23
23
 
24
- if RUBY_VERSION =~ /^1.9/
25
- def test_input_must_be_utf8_or_ascii
26
- escaped = EscapeUtils.escape_javascript("dont </close> tags")
27
-
28
- escaped.force_encoding 'ISO-8859-1'
29
- assert_raises Encoding::CompatibilityError do
30
- EscapeUtils.unescape_javascript(escaped)
31
- end
32
-
33
- escaped.force_encoding 'UTF-8'
34
- begin
35
- EscapeUtils.unescape_javascript(escaped)
36
- rescue Encoding::CompatibilityError => e
37
- assert_nil e, "#{e.class.name} raised, expected not to"
38
- end
24
+ def test_input_must_be_utf8_or_ascii
25
+ escaped = EscapeUtils.escape_javascript("dont </close> tags")
26
+
27
+ escaped.force_encoding 'ISO-8859-1'
28
+ assert_raises Encoding::CompatibilityError do
29
+ EscapeUtils.unescape_javascript(escaped)
39
30
  end
40
31
 
41
- def test_return_value_is_tagged_as_utf8
42
- escaped = EscapeUtils.escape_javascript("dont </close> tags")
43
- assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_javascript(escaped).encoding
32
+ escaped.force_encoding 'UTF-8'
33
+ begin
34
+ EscapeUtils.unescape_javascript(escaped)
35
+ rescue Encoding::CompatibilityError => e
36
+ assert_nil e, "#{e.class.name} raised, expected not to"
44
37
  end
45
38
  end
39
+
40
+ def test_return_value_is_tagged_as_utf8
41
+ escaped = EscapeUtils.escape_javascript("dont </close> tags")
42
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_javascript(escaped).encoding
43
+ end
46
44
  end
@@ -25,26 +25,24 @@ class QueryEscapeTest < Minitest::Test
25
25
  assert_equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8', EscapeUtils.escape_url(matz_name_sep)
26
26
  end
27
27
 
28
- if RUBY_VERSION =~ /^1.9/
29
- def test_input_must_be_utf8_or_ascii
30
- str = "a space"
31
-
32
- str.force_encoding 'ISO-8859-1'
33
- assert_raises Encoding::CompatibilityError do
34
- EscapeUtils.escape_url(str)
35
- end
36
-
37
- str.force_encoding 'UTF-8'
38
- begin
39
- EscapeUtils.escape_url(str)
40
- rescue Encoding::CompatibilityError => e
41
- assert_nil e, "#{e.class.name} raised, expected not to"
42
- end
28
+ def test_input_must_be_utf8_or_ascii
29
+ str = "a space"
30
+
31
+ str.force_encoding 'ISO-8859-1'
32
+ assert_raises Encoding::CompatibilityError do
33
+ EscapeUtils.escape_url(str)
43
34
  end
44
35
 
45
- def test_return_value_is_tagged_as_utf8
46
- str = "a+space"
47
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
36
+ str.force_encoding 'UTF-8'
37
+ begin
38
+ EscapeUtils.escape_url(str)
39
+ rescue Encoding::CompatibilityError => e
40
+ assert_nil e, "#{e.class.name} raised, expected not to"
48
41
  end
49
42
  end
43
+
44
+ def test_return_value_is_tagged_as_utf8
45
+ str = "a+space"
46
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
47
+ end
50
48
  end
@@ -27,26 +27,24 @@ class QueryUnescapeTest < Minitest::Test
27
27
  assert_equal matz_name_sep, EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8')
28
28
  end
29
29
 
30
- if RUBY_VERSION =~ /^1.9/
31
- def test_input_must_be_valid_utf8_or_ascii
32
- escaped = EscapeUtils.unescape_url("a+space")
33
-
34
- escaped.force_encoding 'ISO-8859-1'
35
- assert_raises Encoding::CompatibilityError do
36
- EscapeUtils.unescape_url(escaped)
37
- end
38
-
39
- escaped.force_encoding 'UTF-8'
40
- begin
41
- EscapeUtils.unescape_url(escaped)
42
- rescue Encoding::CompatibilityError => e
43
- assert_nil e, "#{e.class.name} raised, expected not to"
44
- end
30
+ def test_input_must_be_valid_utf8_or_ascii
31
+ escaped = EscapeUtils.unescape_url("a+space")
32
+
33
+ escaped.force_encoding 'ISO-8859-1'
34
+ assert_raises Encoding::CompatibilityError do
35
+ EscapeUtils.unescape_url(escaped)
45
36
  end
46
37
 
47
- def test_return_value_is_tagged_as_utf8
48
- escaped = EscapeUtils.escape_url("a space")
49
- assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
38
+ escaped.force_encoding 'UTF-8'
39
+ begin
40
+ EscapeUtils.unescape_url(escaped)
41
+ rescue Encoding::CompatibilityError => e
42
+ assert_nil e, "#{e.class.name} raised, expected not to"
50
43
  end
51
44
  end
45
+
46
+ def test_return_value_is_tagged_as_utf8
47
+ escaped = EscapeUtils.escape_url("a space")
48
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
49
+ end
52
50
  end
@@ -5,7 +5,7 @@ class UriEscapeTest < Minitest::Test
5
5
  def test_uri_stdlib_compatibility
6
6
  (0..127).each do |i|
7
7
  c = i.chr
8
- assert_equal URI.escape(c), EscapeUtils.escape_uri(c)
8
+ assert_equal URI::DEFAULT_PARSER.escape(c), EscapeUtils.escape_uri(c)
9
9
  end
10
10
  end
11
11
 
@@ -33,26 +33,24 @@ class UriEscapeTest < Minitest::Test
33
33
  assert_equal "a/slash", EscapeUtils.escape_uri("a/slash")
34
34
  end
35
35
 
36
- if RUBY_VERSION =~ /^1.9/
37
- def test_input_must_be_utf8_or_ascii
38
- str = "fo<o>bar"
36
+ def test_input_must_be_utf8_or_ascii
37
+ str = "fo<o>bar"
39
38
 
40
- str.force_encoding 'ISO-8859-1'
41
- assert_raises Encoding::CompatibilityError do
42
- EscapeUtils.escape_uri(str)
43
- end
44
-
45
- str.force_encoding 'UTF-8'
46
- begin
47
- EscapeUtils.escape_uri(str)
48
- rescue Encoding::CompatibilityError => e
49
- assert_nil e, "#{e.class.name} raised, expected not to"
50
- end
39
+ str.force_encoding 'ISO-8859-1'
40
+ assert_raises Encoding::CompatibilityError do
41
+ EscapeUtils.escape_uri(str)
51
42
  end
52
43
 
53
- def test_return_value_is_tagged_as_utf8
54
- str = "fo<o>bar"
55
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_uri(str).encoding
44
+ str.force_encoding 'UTF-8'
45
+ begin
46
+ EscapeUtils.escape_uri(str)
47
+ rescue Encoding::CompatibilityError => e
48
+ assert_nil e, "#{e.class.name} raised, expected not to"
56
49
  end
57
50
  end
51
+
52
+ def test_return_value_is_tagged_as_utf8
53
+ str = "fo<o>bar"
54
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_uri(str).encoding
55
+ end
58
56
  end
@@ -41,26 +41,24 @@ class UriUnescapeTest < Minitest::Test
41
41
  end
42
42
  end
43
43
 
44
- if RUBY_VERSION =~ /^1.9/
45
- def test_input_must_be_valid_utf8_or_ascii
46
- escaped = EscapeUtils.escape_uri("fo<o>bar")
44
+ def test_input_must_be_valid_utf8_or_ascii
45
+ escaped = EscapeUtils.escape_uri("fo<o>bar")
47
46
 
48
- escaped.force_encoding 'ISO-8859-1'
49
- assert_raises Encoding::CompatibilityError do
50
- EscapeUtils.unescape_uri(escaped)
51
- end
52
-
53
- escaped.force_encoding 'UTF-8'
54
- begin
55
- EscapeUtils.unescape_uri(escaped)
56
- rescue Encoding::CompatibilityError => e
57
- assert_nil e, "#{e.class.name} raised, expected not to"
58
- end
47
+ escaped.force_encoding 'ISO-8859-1'
48
+ assert_raises Encoding::CompatibilityError do
49
+ EscapeUtils.unescape_uri(escaped)
59
50
  end
60
51
 
61
- def test_return_value_is_tagged_as_utf8
62
- escaped = EscapeUtils.escape_uri("a space")
63
- assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_uri(escaped).encoding
52
+ escaped.force_encoding 'UTF-8'
53
+ begin
54
+ EscapeUtils.unescape_uri(escaped)
55
+ rescue Encoding::CompatibilityError => e
56
+ assert_nil e, "#{e.class.name} raised, expected not to"
64
57
  end
65
58
  end
59
+
60
+ def test_return_value_is_tagged_as_utf8
61
+ escaped = EscapeUtils.escape_uri("a space")
62
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_uri(escaped).encoding
63
+ end
66
64
  end
@@ -43,26 +43,24 @@ class UriComponentEscapeTest < Minitest::Test
43
43
  assert_equal "a%2Fslash", EscapeUtils.escape_uri_component("a/slash")
44
44
  end
45
45
 
46
- if RUBY_VERSION =~ /^1.9/
47
- def test_input_must_be_utf8_or_ascii
48
- str = "fo<o>bar"
46
+ def test_input_must_be_utf8_or_ascii
47
+ str = "fo<o>bar"
49
48
 
50
- str.force_encoding 'ISO-8859-1'
51
- assert_raises Encoding::CompatibilityError do
52
- EscapeUtils.escape_uri_component(str)
53
- end
54
-
55
- str.force_encoding 'UTF-8'
56
- begin
57
- EscapeUtils.escape_uri_component(str)
58
- rescue Encoding::CompatibilityError => e
59
- assert_nil e, "#{e.class.name} raised, expected not to"
60
- end
49
+ str.force_encoding 'ISO-8859-1'
50
+ assert_raises Encoding::CompatibilityError do
51
+ EscapeUtils.escape_uri_component(str)
61
52
  end
62
53
 
63
- def test_return_value_is_tagged_as_utf8
64
- str = "fo<o>bar"
65
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_uri_component(str).encoding
54
+ str.force_encoding 'UTF-8'
55
+ begin
56
+ EscapeUtils.escape_uri_component(str)
57
+ rescue Encoding::CompatibilityError => e
58
+ assert_nil e, "#{e.class.name} raised, expected not to"
66
59
  end
67
60
  end
61
+
62
+ def test_return_value_is_tagged_as_utf8
63
+ str = "fo<o>bar"
64
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_uri_component(str).encoding
65
+ end
68
66
  end
@@ -46,26 +46,24 @@ class UriComponentUnescapeTest < Minitest::Test
46
46
  assert_equal matz_name_sep, EscapeUtils.unescape_uri_component('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8')
47
47
  end
48
48
 
49
- if RUBY_VERSION =~ /^1.9/
50
- def test_input_must_be_valid_utf8_or_ascii
51
- escaped = EscapeUtils.escape_uri_component("fo<o>bar")
49
+ def test_input_must_be_valid_utf8_or_ascii
50
+ escaped = EscapeUtils.escape_uri_component("fo<o>bar")
52
51
 
53
- escaped.force_encoding 'ISO-8859-1'
54
- assert_raises Encoding::CompatibilityError do
55
- EscapeUtils.unescape_uri_component(escaped)
56
- end
57
-
58
- escaped.force_encoding 'UTF-8'
59
- begin
60
- EscapeUtils.unescape_uri_component(escaped)
61
- rescue Encoding::CompatibilityError => e
62
- assert_nil e, "#{e.class.name} raised, expected not to"
63
- end
52
+ escaped.force_encoding 'ISO-8859-1'
53
+ assert_raises Encoding::CompatibilityError do
54
+ EscapeUtils.unescape_uri_component(escaped)
64
55
  end
65
56
 
66
- def test_return_value_is_tagged_as_utf8
67
- escaped = EscapeUtils.escape_uri_component("fo<o>bar")
68
- assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_uri_component(escaped).encoding
57
+ escaped.force_encoding 'UTF-8'
58
+ begin
59
+ EscapeUtils.unescape_uri_component(escaped)
60
+ rescue Encoding::CompatibilityError => e
61
+ assert_nil e, "#{e.class.name} raised, expected not to"
69
62
  end
70
63
  end
64
+
65
+ def test_return_value_is_tagged_as_utf8
66
+ escaped = EscapeUtils.escape_uri_component("fo<o>bar")
67
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_uri_component(escaped).encoding
68
+ end
71
69
  end
@@ -41,26 +41,24 @@ class UrlEscapeTest < Minitest::Test
41
41
  assert_equal "a%2Fslash", EscapeUtils.escape_url("a/slash")
42
42
  end
43
43
 
44
- if RUBY_VERSION =~ /^1.9/
45
- def test_input_must_be_utf8_or_ascii
46
- str = "fo<o>bar"
44
+ def test_input_must_be_utf8_or_ascii
45
+ str = "fo<o>bar"
47
46
 
48
- str.force_encoding 'ISO-8859-1'
49
- assert_raises Encoding::CompatibilityError do
50
- EscapeUtils.escape_url(str)
51
- end
52
-
53
- str.force_encoding 'UTF-8'
54
- begin
55
- EscapeUtils.escape_url(str)
56
- rescue Encoding::CompatibilityError => e
57
- assert_nil e, "#{e.class.name} raised, expected not to"
58
- end
47
+ str.force_encoding 'ISO-8859-1'
48
+ assert_raises Encoding::CompatibilityError do
49
+ EscapeUtils.escape_url(str)
59
50
  end
60
51
 
61
- def test_return_value_is_tagged_as_utf8
62
- str = "fo<o>bar"
63
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
52
+ str.force_encoding 'UTF-8'
53
+ begin
54
+ EscapeUtils.escape_url(str)
55
+ rescue Encoding::CompatibilityError => e
56
+ assert_nil e, "#{e.class.name} raised, expected not to"
64
57
  end
65
58
  end
59
+
60
+ def test_return_value_is_tagged_as_utf8
61
+ str = "fo<o>bar"
62
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
63
+ end
66
64
  end
@@ -46,26 +46,24 @@ class UrlUnescapeTest < Minitest::Test
46
46
  end
47
47
  end
48
48
 
49
- if RUBY_VERSION =~ /^1.9/
50
- def test_input_must_be_valid_utf8_or_ascii
51
- escaped = EscapeUtils.escape_url("fo<o>bar")
49
+ def test_input_must_be_valid_utf8_or_ascii
50
+ escaped = EscapeUtils.escape_url("fo<o>bar")
52
51
 
53
- escaped.force_encoding 'ISO-8859-1'
54
- assert_raises Encoding::CompatibilityError do
55
- EscapeUtils.unescape_url(escaped)
56
- end
57
-
58
- escaped.force_encoding 'UTF-8'
59
- begin
60
- EscapeUtils.unescape_url(escaped)
61
- rescue Encoding::CompatibilityError => e
62
- assert_nil e, "#{e.class.name} raised, expected not to"
63
- end
52
+ escaped.force_encoding 'ISO-8859-1'
53
+ assert_raises Encoding::CompatibilityError do
54
+ EscapeUtils.unescape_url(escaped)
64
55
  end
65
56
 
66
- def test_return_value_is_tagged_as_utf8
67
- escaped = EscapeUtils.escape_url("fo<o>bar")
68
- assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
57
+ escaped.force_encoding 'UTF-8'
58
+ begin
59
+ EscapeUtils.unescape_url(escaped)
60
+ rescue Encoding::CompatibilityError => e
61
+ assert_nil e, "#{e.class.name} raised, expected not to"
69
62
  end
70
63
  end
64
+
65
+ def test_return_value_is_tagged_as_utf8
66
+ escaped = EscapeUtils.escape_url("fo<o>bar")
67
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
68
+ end
71
69
  end
@@ -42,26 +42,24 @@ class XmlEscapeTest < Minitest::Test
42
42
  end
43
43
  end
44
44
 
45
- if RUBY_VERSION =~ /^1.9/
46
- def test_input_must_be_utf8_or_ascii
47
- str = "<some_tag/>"
45
+ def test_input_must_be_utf8_or_ascii
46
+ str = "<some_tag/>"
48
47
 
49
- str.force_encoding 'ISO-8859-1'
50
- assert_raises Encoding::CompatibilityError do
51
- EscapeUtils.escape_xml(str)
52
- end
53
-
54
- str.force_encoding 'UTF-8'
55
- begin
56
- EscapeUtils.escape_xml(str)
57
- rescue Encoding::CompatibilityError => e
58
- assert_nil e, "#{e.class.name} raised, expected not to"
59
- end
48
+ str.force_encoding 'ISO-8859-1'
49
+ assert_raises Encoding::CompatibilityError do
50
+ EscapeUtils.escape_xml(str)
60
51
  end
61
52
 
62
- def test_return_value_is_tagged_as_utf8
63
- str = "<some_tag/>"
64
- assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
53
+ str.force_encoding 'UTF-8'
54
+ begin
55
+ EscapeUtils.escape_xml(str)
56
+ rescue Encoding::CompatibilityError => e
57
+ assert_nil e, "#{e.class.name} raised, expected not to"
65
58
  end
66
59
  end
60
+
61
+ def test_return_value_is_tagged_as_utf8
62
+ str = "<some_tag/>"
63
+ assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
64
+ end
67
65
  end
metadata CHANGED
@@ -1,127 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escape_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake-compiler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.7.5
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.7.5
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 5.0.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 5.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: benchmark-ips
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rack
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: haml
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: fast_xs
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: actionpack
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: url_escape
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
+ dependencies: []
125
13
  description: Quickly perform HTML, URL, URI and Javascript escaping/unescaping
126
14
  email: seniorlopez@gmail.com
127
15
  executables: []
@@ -129,8 +17,9 @@ extensions:
129
17
  - ext/escape_utils/extconf.rb
130
18
  extra_rdoc_files: []
131
19
  files:
20
+ - ".github/workflows/ci.yml"
132
21
  - ".gitignore"
133
- - ".travis.yml"
22
+ - CHANGELOG.md
134
23
  - Gemfile
135
24
  - LICENSE
136
25
  - README.md
@@ -142,6 +31,7 @@ files:
142
31
  - benchmark/url_escape.rb
143
32
  - benchmark/url_unescape.rb
144
33
  - benchmark/xml_escape.rb
34
+ - bin/console
145
35
  - escape_utils.gemspec
146
36
  - ext/escape_utils/buffer.c
147
37
  - ext/escape_utils/buffer.h
@@ -191,7 +81,7 @@ homepage: https://github.com/brianmario/escape_utils
191
81
  licenses:
192
82
  - MIT
193
83
  metadata: {}
194
- post_install_message:
84
+ post_install_message:
195
85
  rdoc_options:
196
86
  - "--charset=UTF-8"
197
87
  require_paths:
@@ -200,16 +90,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
90
  requirements:
201
91
  - - ">="
202
92
  - !ruby/object:Gem::Version
203
- version: 1.9.3
93
+ version: '2.5'
204
94
  required_rubygems_version: !ruby/object:Gem::Requirement
205
95
  requirements:
206
96
  - - ">="
207
97
  - !ruby/object:Gem::Version
208
98
  version: '0'
209
99
  requirements: []
210
- rubyforge_project:
211
- rubygems_version: 2.5.1
212
- signing_key:
100
+ rubygems_version: 3.3.7
101
+ signing_key:
213
102
  specification_version: 4
214
103
  summary: Faster string escaping routines for your web apps
215
104
  test_files:
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.0
7
- - 2.3.0