escape_utils 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e59c356d88fb33a0a31f0668c2e476d45bcced9
4
+ data.tar.gz: a8df94fbbc6f8aed27e5c59d53678f944ef782da
5
+ SHA512:
6
+ metadata.gz: 980b6eef8962eac5f49e61154e1a26018c4e6a1be57a3d3c7aaa5acab8dac52076750edab093d3b0ed8ea47a00d7d222520251ed5f9a8bf6885d2e26e39d034e
7
+ data.tar.gz: 09ccd6442abd623df06036d418833af4d3bd1b63ee74f582f08f0537dccc7f29405ed934b7d2c0edbdab0d1c956a44946b2e8709f62ba1a214f28f814bdd1a28
data/.travis.yml CHANGED
@@ -1,13 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
6
4
  - 2.0.0
7
- - ree
8
- - rbx-18mode
9
5
  - rbx-19mode
10
6
  matrix:
11
7
  allow_failures:
12
- - rvm: rbx-18mode
13
8
  - rvm: rbx-19mode
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
data/README.md CHANGED
@@ -10,6 +10,8 @@ It supports HTML, URL, URI and Javascript escaping/unescaping.
10
10
 
11
11
  ## Installing
12
12
 
13
+ Compatible with Ruby 1.9.3+
14
+
13
15
  ``` sh
14
16
  gem install escape_utils
15
17
  ```
@@ -18,20 +20,11 @@ gem install escape_utils
18
20
 
19
21
  escape_utils assumes all input is encoded as valid UTF-8. If you are dealing with other encodings do your best to transcode the string into a UTF-8 byte stream before handing it to escape_utils.
20
22
 
21
- On Ruby 1.9 this is as easy as:
22
23
 
23
24
  ``` ruby
24
25
  utf8_string = non_utf8_string.encode('UTF-8')
25
26
  ```
26
27
 
27
- If you're on Ruby 1.8 you can use [charlock_holmes](https://github.com/brianmario/charlock_holmes) to transcode like so:
28
-
29
- ``` ruby
30
- # NOTE: we're assuming you know the encoding of `non_utf8_string` here.
31
- # if you don't, you can use the detection API of charlock_holmes
32
- utf8_string = CharlockHolmes::Converter.convert(non_utf8_string, other_encoding, 'UTF-8')
33
- ```
34
-
35
28
  ## Usage
36
29
 
37
30
  ### HTML
data/escape_utils.gemspec CHANGED
@@ -14,9 +14,11 @@ Gem::Specification.new do |s|
14
14
  s.summary = %q{Faster string escaping routines for your web apps}
15
15
  s.test_files = `git ls-files test`.split("\n")
16
16
 
17
+ s.required_ruby_version = "> 1.9.3"
18
+
17
19
  # tests
18
20
  s.add_development_dependency 'rake-compiler', ">= 0.7.5"
19
- s.add_development_dependency 'minitest'
21
+ s.add_development_dependency 'minitest', ">= 5.0.0"
20
22
  # benchmarks
21
23
  s.add_development_dependency 'rack'
22
24
  s.add_development_dependency 'haml'
@@ -4,10 +4,9 @@
4
4
  #define RSTRING_NOT_MODIFIED
5
5
 
6
6
  #include <ruby.h>
7
+ #include <ruby/encoding.h>
7
8
  #include "houdini.h"
8
9
 
9
- #ifdef HAVE_RUBY_ENCODING_H
10
- #include <ruby/encoding.h>
11
10
  static VALUE rb_eEncodingCompatibilityError;
12
11
 
13
12
  static VALUE eu_new_str(const char *str, size_t len)
@@ -32,14 +31,6 @@ static void check_utf8_encoding(VALUE str)
32
31
  "Input must be UTF-8 or US-ASCII, %s given", rb_enc_name(enc));
33
32
  }
34
33
  }
35
- #else
36
- static VALUE eu_new_str(const char *str, size_t len)
37
- {
38
- return rb_str_new(str, len);
39
- }
40
-
41
- static void check_utf8_encoding(VALUE str) {}
42
- #endif
43
34
 
44
35
  typedef int (*houdini_cb)(gh_buf *, const uint8_t *, size_t);
45
36
 
@@ -62,6 +53,7 @@ static VALUE rb_eu_set_html_secure(VALUE self, VALUE val)
62
53
  * html_safe_string_class instance variable
63
54
  */
64
55
  static VALUE rb_html_safe_string_class;
56
+ static VALUE rb_html_safe_string_template_object;
65
57
 
66
58
  static VALUE rb_eu_set_html_safe_string_class(VALUE self, VALUE val)
67
59
  {
@@ -71,6 +63,8 @@ static VALUE rb_eu_set_html_safe_string_class(VALUE self, VALUE val)
71
63
  rb_raise(rb_eArgError, "%s must be a descendent of String", rb_class2name(val));
72
64
 
73
65
  rb_html_safe_string_class = val;
66
+ rb_html_safe_string_template_object = rb_class_new_instance(0, NULL, rb_html_safe_string_class);
67
+ OBJ_FREEZE(rb_html_safe_string_template_object);
74
68
  rb_ivar_set(self, rb_intern("@html_safe_string_class"), val);
75
69
  return val;
76
70
  }
@@ -115,19 +109,10 @@ static VALUE rb_eu_escape_html_as_html_safe(VALUE self, VALUE str)
115
109
  result = eu_new_str(buf.ptr, buf.size);
116
110
  gh_buf_free(&buf);
117
111
  } else {
118
- #ifdef RBASIC
119
- result = rb_str_dup(str);
120
- #else
121
- result = str;
122
- #endif
112
+ result = rb_str_new_with_class(rb_html_safe_string_template_object,
113
+ RSTRING_PTR(str), RSTRING_LEN(str));
123
114
  }
124
115
 
125
- #ifdef RBASIC
126
- RBASIC(result)->klass = rb_html_safe_string_class;
127
- #else
128
- result = rb_funcall(rb_html_safe_string_class, ID_new, 1, result);
129
- #endif
130
-
131
116
  rb_ivar_set(result, ID_at_html_safe, Qtrue);
132
117
 
133
118
  return result;
@@ -217,16 +202,17 @@ static VALUE rb_eu_unescape_uri(VALUE self, VALUE str)
217
202
  /**
218
203
  * Ruby Extension initializer
219
204
  */
205
+ __attribute__((visibility("default")))
220
206
  void Init_escape_utils()
221
207
  {
222
- #ifdef HAVE_RUBY_ENCODING_H
223
208
  rb_eEncodingCompatibilityError = rb_const_get(rb_cEncoding, rb_intern("CompatibilityError"));
224
- #endif
225
209
 
226
210
  ID_new = rb_intern("new");
227
211
  ID_at_html_safe = rb_intern("@html_safe");
228
- rb_mEscapeUtils = rb_define_module("EscapeUtils");
212
+ rb_global_variable(&rb_html_safe_string_class);
213
+ rb_global_variable(&rb_html_safe_string_template_object);
229
214
 
215
+ rb_mEscapeUtils = rb_define_module("EscapeUtils");
230
216
  rb_define_method(rb_mEscapeUtils, "escape_html_as_html_safe", rb_eu_escape_html_as_html_safe, 1);
231
217
  rb_define_method(rb_mEscapeUtils, "escape_html", rb_eu_escape_html, -1);
232
218
  rb_define_method(rb_mEscapeUtils, "unescape_html", rb_eu_unescape_html, 1);
@@ -1,6 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
- $CFLAGS << ' -Wall -funroll-loops'
3
+ $CFLAGS << ' -Wall -funroll-loops -fvisibility=hidden'
4
4
  $CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG']
5
5
 
6
6
  create_makefile("escape_utils/escape_utils")
@@ -1,3 +1,3 @@
1
1
  module EscapeUtils
2
- VERSION = "0.3.2"
3
- end
2
+ VERSION = "1.0.0"
3
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,2 @@
1
+ bundle install --path vendor/gems --binstubs
2
+ bin/rake clobber clean compile
@@ -3,7 +3,7 @@ require File.expand_path("../../helper", __FILE__)
3
3
  class MyCustomHtmlSafeString < String
4
4
  end
5
5
 
6
- class HtmlEscapeTest < MiniTest::Unit::TestCase
6
+ class HtmlEscapeTest < Minitest::Test
7
7
  def test_escape_basic_html_with_secure
8
8
  assert_equal "&lt;some_tag&#47;&gt;", EscapeUtils.escape_html("<some_tag/>")
9
9
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require File.expand_path("../../helper", __FILE__)
3
3
 
4
- class HtmlUnescapeTest < MiniTest::Unit::TestCase
4
+ class HtmlUnescapeTest < Minitest::Test
5
5
  def test_basic_html
6
6
  assert_equal "<some_tag/>", EscapeUtils.unescape_html("&lt;some_tag&#47;&gt;")
7
7
  end
@@ -45,4 +45,4 @@ class HtmlUnescapeTest < MiniTest::Unit::TestCase
45
45
  assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_html(escaped).encoding
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -26,7 +26,7 @@ class String
26
26
  end
27
27
  end
28
28
 
29
- class HtmlEscapeTest < MiniTest::Unit::TestCase
29
+ class HtmlEscapeTest < Minitest::Test
30
30
  include EscapeUtils::HtmlSafety
31
31
 
32
32
  def test_marks_escaped_strings_safe
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class JavascriptEscapeTest < MiniTest::Unit::TestCase
3
+ class JavascriptEscapeTest < Minitest::Test
4
4
  def test_returns_empty_string_if_nil_passed
5
5
  assert_equal "", EscapeUtils.escape_javascript(nil)
6
6
  end
@@ -39,4 +39,4 @@ class JavascriptEscapeTest < MiniTest::Unit::TestCase
39
39
  assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_javascript(str).encoding
40
40
  end
41
41
  end
42
- end
42
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class JavascriptUnescapeTest < MiniTest::Unit::TestCase
3
+ class JavascriptUnescapeTest < Minitest::Test
4
4
  def test_returns_empty_string_if_nil_passed
5
5
  assert_equal "", EscapeUtils.unescape_javascript(nil)
6
6
  end
@@ -43,4 +43,4 @@ class JavascriptUnescapeTest < MiniTest::Unit::TestCase
43
43
  assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_javascript(escaped).encoding
44
44
  end
45
45
  end
46
- end
46
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class QueryEscapeTest < MiniTest::Unit::TestCase
3
+ class QueryEscapeTest < Minitest::Test
4
4
  def test_basic_url
5
5
  assert_equal "http%3A%2F%2Fwww.homerun.com%2F", EscapeUtils.escape_url("http://www.homerun.com/")
6
6
  end
@@ -47,4 +47,4 @@ class QueryEscapeTest < MiniTest::Unit::TestCase
47
47
  assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class QueryUnescapeTest < MiniTest::Unit::TestCase
3
+ class QueryUnescapeTest < Minitest::Test
4
4
  def test_basic_url
5
5
  assert_equal "http://www.homerun.com/", EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F")
6
6
  end
@@ -49,4 +49,4 @@ class QueryUnescapeTest < MiniTest::Unit::TestCase
49
49
  assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
50
50
  end
51
51
  end
52
- end
52
+ end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
  require 'uri'
3
3
 
4
- class UriEscapeTest < MiniTest::Unit::TestCase
4
+ class UriEscapeTest < Minitest::Test
5
5
  def test_uri_stdlib_compatibility
6
6
  (0..127).each do |i|
7
7
  c = i.chr
@@ -47,4 +47,4 @@ class UriEscapeTest < MiniTest::Unit::TestCase
47
47
  assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_uri(str).encoding
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class UriUnescapeTest < MiniTest::Unit::TestCase
3
+ class UriUnescapeTest < Minitest::Test
4
4
  def test_doesnt_unescape_an_incomplete_escape
5
5
  assert_equal "%", EscapeUtils.unescape_uri("%")
6
6
  assert_equal "http%", EscapeUtils.unescape_uri("http%")
@@ -52,4 +52,4 @@ class UriUnescapeTest < MiniTest::Unit::TestCase
52
52
  assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
53
53
  end
54
54
  end
55
- end
55
+ end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
  require 'cgi'
3
3
 
4
- class UriEscapeTest < MiniTest::Unit::TestCase
4
+ class UriEscapeTest < Minitest::Test
5
5
  def test_basic_url
6
6
  assert_equal "http%3A%2F%2Fwww.homerun.com%2F", EscapeUtils.escape_url("http://www.homerun.com/")
7
7
  end
@@ -55,4 +55,4 @@ class UriEscapeTest < MiniTest::Unit::TestCase
55
55
  assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_url(str).encoding
56
56
  end
57
57
  end
58
- end
58
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class UriUnescapeTest < MiniTest::Unit::TestCase
3
+ class UriUnescapeTest < Minitest::Test
4
4
  def test_basic_url
5
5
  assert_equal "http://www.homerun.com/", EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F")
6
6
  assert_equal "http://www.homerun.com/", EscapeUtils.unescape_url("http://www.homerun.com/")
@@ -57,4 +57,4 @@ class UriUnescapeTest < MiniTest::Unit::TestCase
57
57
  assert_equal Encoding.find('UTF-8'), EscapeUtils.unescape_url(escaped).encoding
58
58
  end
59
59
  end
60
- end
60
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../helper", __FILE__)
2
2
 
3
- class XmlEscapeTest < MiniTest::Unit::TestCase
3
+ class XmlEscapeTest < Minitest::Test
4
4
  def test_basic_xml
5
5
  assert_equal "&lt;some_tag/&gt;", EscapeUtils.escape_xml("<some_tag/>")
6
6
  end
metadata CHANGED
@@ -1,126 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escape_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Lopez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.7.5
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.7.5
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: 5.0.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: 5.0.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rack
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: haml
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: fast_xs
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: actionpack
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: url_escape
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description:
@@ -172,6 +157,7 @@ files:
172
157
  - lib/escape_utils/url/uri.rb
173
158
  - lib/escape_utils/version.rb
174
159
  - lib/escape_utils/xml/builder.rb
160
+ - script/bootstrap
175
161
  - test/helper.rb
176
162
  - test/html/escape_test.rb
177
163
  - test/html/unescape_test.rb
@@ -187,28 +173,27 @@ files:
187
173
  - test/xml/escape_test.rb
188
174
  homepage: http://github.com/brianmario/escape_utils
189
175
  licenses: []
176
+ metadata: {}
190
177
  post_install_message:
191
178
  rdoc_options:
192
179
  - --charset=UTF-8
193
180
  require_paths:
194
181
  - lib
195
182
  required_ruby_version: !ruby/object:Gem::Requirement
196
- none: false
197
183
  requirements:
198
- - - ! '>='
184
+ - - '>'
199
185
  - !ruby/object:Gem::Version
200
- version: '0'
186
+ version: 1.9.3
201
187
  required_rubygems_version: !ruby/object:Gem::Requirement
202
- none: false
203
188
  requirements:
204
- - - ! '>='
189
+ - - '>='
205
190
  - !ruby/object:Gem::Version
206
191
  version: '0'
207
192
  requirements: []
208
193
  rubyforge_project:
209
- rubygems_version: 1.8.23
194
+ rubygems_version: 2.0.3
210
195
  signing_key:
211
- specification_version: 3
196
+ specification_version: 4
212
197
  summary: Faster string escaping routines for your web apps
213
198
  test_files:
214
199
  - test/helper.rb