escape_utils 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.5 (September 6th, 2010)
3
+ ## 0.1.7 (September 29th, 2010)
4
+ * fix URI escaping to act according to the RFC
5
+ * add specs for URL escaping
6
+
7
+ ## 0.1.6 (September 6th, 2010)
4
8
  * support for URI escaping added (thanks to @joshbuddy)
5
9
  * bugfix to ensure we don't drop opening tags during escape_javascript (thanks to @nagybence)
6
10
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
data/escape_utils.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{escape_utils}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Lopez"]
12
- s.date = %q{2010-09-06}
12
+ s.date = %q{2010-09-29}
13
13
  s.email = %q{seniorlopez@gmail.com}
14
14
  s.extensions = ["ext/extconf.rb"]
15
15
  s.extra_rdoc_files = [
@@ -53,7 +53,9 @@ Gem::Specification.new do |s|
53
53
  "spec/spec.opts",
54
54
  "spec/spec_helper.rb",
55
55
  "spec/uri/escape_spec.rb",
56
- "spec/uri/unescape_spec.rb"
56
+ "spec/uri/unescape_spec.rb",
57
+ "spec/url/escape_spec.rb",
58
+ "spec/url/unescape_spec.rb"
57
59
  ]
58
60
  s.homepage = %q{http://github.com/brianmario/escape_utils}
59
61
  s.rdoc_options = ["--charset=UTF-8"]
@@ -70,7 +72,9 @@ Gem::Specification.new do |s|
70
72
  "spec/query/unescape_spec.rb",
71
73
  "spec/spec_helper.rb",
72
74
  "spec/uri/escape_spec.rb",
73
- "spec/uri/unescape_spec.rb"
75
+ "spec/uri/unescape_spec.rb",
76
+ "spec/url/escape_spec.rb",
77
+ "spec/url/unescape_spec.rb"
74
78
  ]
75
79
 
76
80
  if s.respond_to? :specification_version then
data/ext/escape_utils.c CHANGED
@@ -7,8 +7,8 @@ static rb_encoding *utf8Encoding;
7
7
  #define IS_HEX(c) (c >= 48 || c <= 57) && (c >= 65 || c <= 70) && (c >= 97 || c <= 102)
8
8
  #define NOT_HEX(c) (c < 48 || c > 57) && (c < 65 || c > 90) && (c < 97 || c > 122)
9
9
  #define UNHEX(c) (c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : c - 'a' + 10)
10
- #define URI_SAFE(c) (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= 38 && c <= 47) || c == 33 || c == 36 || c == 58 || c == 59 || c == 61 || c == 63 || c == 64 || c == 91 || c == 93 || c == 95 || c == 126
11
- // \.:\/?\[\]\-_~\!\$&'\(\)\*\+,;=@
10
+ #define URI_SAFE(c) (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= 38 && c <= 47) || c == 95 || c == 126
11
+ // ALPHA / DIGIT / "-" / "." / "_" / "~"
12
12
 
13
13
  static size_t escape_html(unsigned char *out, const unsigned char *in, size_t in_len) {
14
14
  size_t total = 0;
data/lib/escape_utils.rb CHANGED
@@ -4,7 +4,7 @@ require 'escape_utils_ext'
4
4
 
5
5
  EscapeUtils.send(:extend, EscapeUtils)
6
6
  module EscapeUtils
7
- VERSION = "0.1.6"
7
+ VERSION = "0.1.7"
8
8
 
9
9
  autoload :HtmlSafety, 'escape_utils/html_safety'
10
10
  end
@@ -7,7 +7,7 @@ describe EscapeUtils, "escape_uri" do
7
7
  end
8
8
 
9
9
  it "should escape a basic url" do
10
- EscapeUtils.escape_uri("http://www.homerun.com/").should eql("http://www.homerun.com/")
10
+ EscapeUtils.escape_uri("http://www.homerun.com/").should eql("http%3A//www.homerun.com/")
11
11
  end
12
12
 
13
13
  # NOTE: from Rack's test suite
@@ -23,7 +23,7 @@ describe EscapeUtils, "escape_uri" do
23
23
 
24
24
  # NOTE: from Rack's test suite
25
25
  it "should escape a string of mixed characters" do
26
- EscapeUtils.escape_uri("q1!2\"'w$5&7/z8)?\\").should eql("q1!2%22'w$5&7/z8)?%5C")
26
+ EscapeUtils.escape_uri("q1!2\"'w$5&7/z8)?\\").should eql("q1%212%22'w%245&7/z8)%3F%5C")
27
27
  end
28
28
 
29
29
  # NOTE: from Rack's test suite
@@ -0,0 +1,52 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
3
+
4
+ describe EscapeUtils, "escape_url" do
5
+ it "should respond to escape_url" do
6
+ EscapeUtils.should respond_to(:escape_url)
7
+ end
8
+
9
+ it "should escape a basic url" do
10
+ EscapeUtils.escape_url("http://www.homerun.com/").should eql("http%3A%2F%2Fwww.homerun.com%2F")
11
+ end
12
+
13
+ # NOTE: from Rack's test suite
14
+ it "should escape a url containing tags" do
15
+ EscapeUtils.escape_url("fo<o>bar").should eql("fo%3Co%3Ebar")
16
+ end
17
+
18
+ # NOTE: from Rack's test suite
19
+ it "should escape a url with spaces" do
20
+ EscapeUtils.escape_url("a space").should eql("a+space")
21
+ EscapeUtils.escape_url("a sp ace ").should eql("a+++sp+ace+")
22
+ end
23
+
24
+ # NOTE: from Rack's test suite
25
+ it "should escape a string of mixed characters" do
26
+ EscapeUtils.escape_url("q1!2\"'w$5&7/z8)?\\").should eql("q1%212%22%27w%245%267%2Fz8%29%3F%5C")
27
+ end
28
+
29
+ # NOTE: from Rack's test suite
30
+ it "should escape correctly for multibyte characters" do
31
+ matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsumoto
32
+ matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
33
+ EscapeUtils.escape_url(matz_name).should eql('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8')
34
+ matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto
35
+ matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
36
+ EscapeUtils.escape_url(matz_name_sep).should eql('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8')
37
+ end
38
+
39
+ if RUBY_VERSION =~ /^1.9/
40
+ it "should default to utf-8 if Encoding.default_internal is nil" do
41
+ Encoding.default_internal = nil
42
+ EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.find('utf-8'))
43
+ end
44
+
45
+ it "should use Encoding.default_internal" do
46
+ Encoding.default_internal = Encoding.find('utf-8')
47
+ EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
48
+ Encoding.default_internal = Encoding.find('us-ascii')
49
+ EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
3
+
4
+ describe EscapeUtils, "unescape_uri" do
5
+ it "should respond to unescape_uri" do
6
+ EscapeUtils.should respond_to(:unescape_uri)
7
+ end
8
+
9
+ it "should unescape a basic url" do
10
+ EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").should eql("http://www.homerun.com/")
11
+ EscapeUtils.unescape_uri("http://www.homerun.com/").should eql("http://www.homerun.com/")
12
+ end
13
+
14
+ # NOTE: from Rack's test suite
15
+ it "should unescape a url containing tags" do
16
+ EscapeUtils.unescape_uri("fo%3Co%3Ebar").should eql("fo<o>bar")
17
+ end
18
+
19
+ # NOTE: from Rack's test suite
20
+ it "should unescape a url with spaces" do
21
+ EscapeUtils.unescape_uri("a%20space").should eql("a space")
22
+ EscapeUtils.unescape_uri("a%20%20%20sp%20ace%20").should eql("a sp ace ")
23
+ EscapeUtils.unescape_uri("a+space").should eql("a+space")
24
+ end
25
+
26
+ # NOTE: from Rack's test suite
27
+ it "should unescape a string of mixed characters" do
28
+ EscapeUtils.unescape_uri("q1%212%22%27w%245%267%2Fz8%29%3F%5C").should eql("q1!2\"'w$5&7/z8)?\\")
29
+ EscapeUtils.unescape_uri("q1!2%22'w$5&7/z8)?%5C").should eql("q1!2\"'w$5&7/z8)?\\")
30
+ end
31
+
32
+ # NOTE: from Rack's test suite
33
+ it "should unescape correctly for multibyte characters" do
34
+ matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsumoto
35
+ matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
36
+ EscapeUtils.unescape_uri('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8').should eql(matz_name)
37
+ matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto
38
+ matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
39
+ EscapeUtils.unescape_uri('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8').should eql(matz_name_sep)
40
+ end
41
+
42
+ if RUBY_VERSION =~ /^1.9/
43
+ it "should default to utf-8 if Encoding.default_internal is nil" do
44
+ Encoding.default_internal = nil
45
+ EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.find('utf-8'))
46
+ end
47
+
48
+ it "should use Encoding.default_internal" do
49
+ Encoding.default_internal = Encoding.find('utf-8')
50
+ EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
51
+ Encoding.default_internal = Encoding.find('us-ascii')
52
+ EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escape_utils
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Lopez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-06 00:00:00 -07:00
18
+ date: 2010-09-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -66,6 +66,8 @@ files:
66
66
  - spec/spec_helper.rb
67
67
  - spec/uri/escape_spec.rb
68
68
  - spec/uri/unescape_spec.rb
69
+ - spec/url/escape_spec.rb
70
+ - spec/url/unescape_spec.rb
69
71
  has_rdoc: true
70
72
  homepage: http://github.com/brianmario/escape_utils
71
73
  licenses: []
@@ -112,3 +114,5 @@ test_files:
112
114
  - spec/spec_helper.rb
113
115
  - spec/uri/escape_spec.rb
114
116
  - spec/uri/unescape_spec.rb
117
+ - spec/url/escape_spec.rb
118
+ - spec/url/unescape_spec.rb