escape_utils 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.travis.yml +13 -0
- data/CHANGELOG.md +7 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +5 -18
- data/benchmark/html_escape.rb +9 -2
- data/benchmark/xml_escape.rb +29 -0
- data/escape_utils.gemspec +2 -3
- data/ext/escape_utils/buffer.c +181 -160
- data/ext/escape_utils/buffer.h +90 -68
- data/ext/escape_utils/escape_utils.c +77 -39
- data/ext/escape_utils/extconf.rb +1 -1
- data/ext/escape_utils/houdini.h +37 -8
- data/ext/escape_utils/houdini_href_e.c +115 -0
- data/ext/escape_utils/houdini_html_e.c +90 -0
- data/ext/escape_utils/houdini_html_u.c +122 -0
- data/ext/escape_utils/{houdini_js.c → houdini_js_e.c} +17 -75
- data/ext/escape_utils/houdini_js_u.c +60 -0
- data/ext/escape_utils/{uri_escape.h → houdini_uri_e.c} +68 -2
- data/ext/escape_utils/houdini_uri_u.c +65 -0
- data/ext/escape_utils/houdini_xml_e.c +136 -0
- data/lib/escape_utils/version.rb +1 -1
- data/lib/escape_utils/xml/builder.rb +8 -0
- data/test/helper.rb +14 -0
- data/test/html/escape_test.rb +61 -0
- data/test/html/unescape_test.rb +48 -0
- data/test/html_safety_test.rb +46 -0
- data/test/javascript/escape_test.rb +42 -0
- data/test/javascript/unescape_test.rb +46 -0
- data/test/query/escape_test.rb +50 -0
- data/test/query/unescape_test.rb +52 -0
- data/test/uri/escape_test.rb +50 -0
- data/test/uri/unescape_test.rb +55 -0
- data/test/url/escape_test.rb +58 -0
- data/test/url/unescape_test.rb +60 -0
- data/test/xml/escape_test.rb +67 -0
- metadata +136 -152
- data/.rspec +0 -2
- data/ext/escape_utils/houdini_html.c +0 -214
- data/ext/escape_utils/houdini_uri.c +0 -130
- data/spec/html/escape_spec.rb +0 -42
- data/spec/html/unescape_spec.rb +0 -37
- data/spec/html_safety_spec.rb +0 -48
- data/spec/javascript/escape_spec.rb +0 -34
- data/spec/javascript/unescape_spec.rb +0 -37
- data/spec/query/escape_spec.rb +0 -44
- data/spec/query/unescape_spec.rb +0 -46
- data/spec/rcov.opts +0 -3
- data/spec/spec_helper.rb +0 -5
- data/spec/uri/escape_spec.rb +0 -43
- data/spec/uri/unescape_spec.rb +0 -57
- data/spec/url/escape_spec.rb +0 -52
- data/spec/url/unescape_spec.rb +0 -57
data/spec/uri/unescape_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
4
|
-
|
5
|
-
describe EscapeUtils, "unescape_uri" do
|
6
|
-
it "should respond to unescape_uri" do
|
7
|
-
EscapeUtils.should respond_to(:unescape_uri)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should unescape a basic url" do
|
11
|
-
EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").should eql("http://www.homerun.com/")
|
12
|
-
EscapeUtils.unescape_uri("http://www.homerun.com/").should eql("http://www.homerun.com/")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should not be thrown by a standalone %" do
|
16
|
-
EscapeUtils.unescape_uri("%").should eql("%")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should not be thrown by a trailing %" do
|
20
|
-
EscapeUtils.unescape_uri("http%").should eql("http%")
|
21
|
-
end
|
22
|
-
|
23
|
-
# NOTE: from Rack's test suite
|
24
|
-
it "should unescape a url containing tags" do
|
25
|
-
EscapeUtils.unescape_uri("fo%3Co%3Ebar").should eql("fo<o>bar")
|
26
|
-
end
|
27
|
-
|
28
|
-
# NOTE: from Rack's test suite
|
29
|
-
it "should unescape a url with spaces" do
|
30
|
-
EscapeUtils.unescape_uri("a%20space").should eql("a space")
|
31
|
-
EscapeUtils.unescape_uri("a%20%20%20sp%20ace%20").should eql("a sp ace ")
|
32
|
-
EscapeUtils.unescape_uri("a+space").should eql("a+space")
|
33
|
-
end
|
34
|
-
|
35
|
-
# NOTE: from Rack's test suite
|
36
|
-
it "should unescape a string of mixed characters" do
|
37
|
-
EscapeUtils.unescape_uri("q1%212%22%27w%245%267%2Fz8%29%3F%5C").should eql("q1!2\"'w$5&7/z8)?\\")
|
38
|
-
EscapeUtils.unescape_uri("q1!2%22'w$5&7/z8)?%5C").should eql("q1!2\"'w$5&7/z8)?\\")
|
39
|
-
end
|
40
|
-
|
41
|
-
# NOTE: from Rack's test suite
|
42
|
-
it "should unescape correctly for multibyte characters" do
|
43
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
44
|
-
EscapeUtils.unescape_uri('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8').should eql(matz_name)
|
45
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
46
|
-
EscapeUtils.unescape_uri('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8').should eql(matz_name_sep)
|
47
|
-
end
|
48
|
-
|
49
|
-
if RUBY_VERSION =~ /^1.9/
|
50
|
-
it "return value should be in original string's encoding" do
|
51
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('us-ascii')
|
52
|
-
EscapeUtils.unescape_uri(str).encoding.should eql(Encoding.find('us-ascii'))
|
53
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('utf-8')
|
54
|
-
EscapeUtils.unescape_uri(str).encoding.should eql(Encoding.find('utf-8'))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/spec/url/escape_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
-
require 'cgi'
|
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
|
-
it "should escape each possible byte value exactly like CGI.escape" do
|
14
|
-
(0..255).each do |i|
|
15
|
-
c = i.chr
|
16
|
-
EscapeUtils.escape_url(c).should eql(CGI.escape(c))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# NOTE: from Rack's test suite
|
21
|
-
it "should escape a url containing tags" do
|
22
|
-
EscapeUtils.escape_url("fo<o>bar").should eql("fo%3Co%3Ebar")
|
23
|
-
end
|
24
|
-
|
25
|
-
# NOTE: from Rack's test suite
|
26
|
-
it "should escape a url with spaces" do
|
27
|
-
EscapeUtils.escape_url("a space").should eql("a+space")
|
28
|
-
EscapeUtils.escape_url("a sp ace ").should eql("a+++sp+ace+")
|
29
|
-
end
|
30
|
-
|
31
|
-
# NOTE: from Rack's test suite
|
32
|
-
it "should escape a string of mixed characters" do
|
33
|
-
EscapeUtils.escape_url("q1!2\"'w$5&7/z8)?\\").should eql("q1%212%22%27w%245%267%2Fz8%29%3F%5C")
|
34
|
-
end
|
35
|
-
|
36
|
-
# NOTE: from Rack's test suite
|
37
|
-
it "should escape correctly for multibyte characters" do
|
38
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
39
|
-
EscapeUtils.escape_url(matz_name).should eql('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8')
|
40
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
41
|
-
EscapeUtils.escape_url(matz_name_sep).should eql('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8')
|
42
|
-
end
|
43
|
-
|
44
|
-
if RUBY_VERSION =~ /^1.9/
|
45
|
-
it "return value should be in original string's encoding" do
|
46
|
-
str = "http://www.homerun.com/".encode('us-ascii')
|
47
|
-
EscapeUtils.escape_url(str).encoding.should eql(Encoding.find('us-ascii'))
|
48
|
-
str = "http://www.homerun.com/".encode('utf-8')
|
49
|
-
EscapeUtils.escape_url(str).encoding.should eql(Encoding.find('utf-8'))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/spec/url/unescape_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
4
|
-
|
5
|
-
describe EscapeUtils, "unescape_url" do
|
6
|
-
it "should respond to unescape_url" do
|
7
|
-
EscapeUtils.should respond_to(:unescape_url)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should unescape a basic url" do
|
11
|
-
EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F").should eql("http://www.homerun.com/")
|
12
|
-
EscapeUtils.unescape_url("http://www.homerun.com/").should eql("http://www.homerun.com/")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should not be thrown by a standalone %" do
|
16
|
-
EscapeUtils.unescape_url("%").should eql("%")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should not be thrown by a trailing %" do
|
20
|
-
EscapeUtils.unescape_url("http%").should eql("http%")
|
21
|
-
end
|
22
|
-
|
23
|
-
# NOTE: from Rack's test suite
|
24
|
-
it "should unescape a url containing tags" do
|
25
|
-
EscapeUtils.unescape_url("fo%3Co%3Ebar").should eql("fo<o>bar")
|
26
|
-
end
|
27
|
-
|
28
|
-
# NOTE: from Rack's test suite
|
29
|
-
it "should unescape a url with spaces" do
|
30
|
-
EscapeUtils.unescape_url("a%20space").should eql("a space")
|
31
|
-
EscapeUtils.unescape_url("a%20%20%20sp%20ace%20").should eql("a sp ace ")
|
32
|
-
EscapeUtils.unescape_url("a+space").should eql("a space")
|
33
|
-
end
|
34
|
-
|
35
|
-
# NOTE: from Rack's test suite
|
36
|
-
it "should unescape a string of mixed characters" do
|
37
|
-
EscapeUtils.unescape_url("q1%212%22%27w%245%267%2Fz8%29%3F%5C").should eql("q1!2\"'w$5&7/z8)?\\")
|
38
|
-
EscapeUtils.unescape_url("q1!2%22'w$5&7/z8)?%5C").should eql("q1!2\"'w$5&7/z8)?\\")
|
39
|
-
end
|
40
|
-
|
41
|
-
# NOTE: from Rack's test suite
|
42
|
-
it "should unescape correctly for multibyte characters" do
|
43
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
44
|
-
EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8').should eql(matz_name)
|
45
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
46
|
-
EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8').should eql(matz_name_sep)
|
47
|
-
end
|
48
|
-
|
49
|
-
if RUBY_VERSION =~ /^1.9/
|
50
|
-
it "return value should be in original string's encoding" do
|
51
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('us-ascii')
|
52
|
-
EscapeUtils.unescape_url(str).encoding.should eql(Encoding.find('us-ascii'))
|
53
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('utf-8')
|
54
|
-
EscapeUtils.unescape_url(str).encoding.should eql(Encoding.find('utf-8'))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|