escape_utils 0.2.4 → 0.3.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.
Files changed (53) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +13 -0
  3. data/CHANGELOG.md +7 -0
  4. data/MIT-LICENSE +1 -1
  5. data/Rakefile +5 -18
  6. data/benchmark/html_escape.rb +9 -2
  7. data/benchmark/xml_escape.rb +29 -0
  8. data/escape_utils.gemspec +2 -3
  9. data/ext/escape_utils/buffer.c +181 -160
  10. data/ext/escape_utils/buffer.h +90 -68
  11. data/ext/escape_utils/escape_utils.c +77 -39
  12. data/ext/escape_utils/extconf.rb +1 -1
  13. data/ext/escape_utils/houdini.h +37 -8
  14. data/ext/escape_utils/houdini_href_e.c +115 -0
  15. data/ext/escape_utils/houdini_html_e.c +90 -0
  16. data/ext/escape_utils/houdini_html_u.c +122 -0
  17. data/ext/escape_utils/{houdini_js.c → houdini_js_e.c} +17 -75
  18. data/ext/escape_utils/houdini_js_u.c +60 -0
  19. data/ext/escape_utils/{uri_escape.h → houdini_uri_e.c} +68 -2
  20. data/ext/escape_utils/houdini_uri_u.c +65 -0
  21. data/ext/escape_utils/houdini_xml_e.c +136 -0
  22. data/lib/escape_utils/version.rb +1 -1
  23. data/lib/escape_utils/xml/builder.rb +8 -0
  24. data/test/helper.rb +14 -0
  25. data/test/html/escape_test.rb +61 -0
  26. data/test/html/unescape_test.rb +48 -0
  27. data/test/html_safety_test.rb +46 -0
  28. data/test/javascript/escape_test.rb +42 -0
  29. data/test/javascript/unescape_test.rb +46 -0
  30. data/test/query/escape_test.rb +50 -0
  31. data/test/query/unescape_test.rb +52 -0
  32. data/test/uri/escape_test.rb +50 -0
  33. data/test/uri/unescape_test.rb +55 -0
  34. data/test/url/escape_test.rb +58 -0
  35. data/test/url/unescape_test.rb +60 -0
  36. data/test/xml/escape_test.rb +67 -0
  37. metadata +136 -152
  38. data/.rspec +0 -2
  39. data/ext/escape_utils/houdini_html.c +0 -214
  40. data/ext/escape_utils/houdini_uri.c +0 -130
  41. data/spec/html/escape_spec.rb +0 -42
  42. data/spec/html/unescape_spec.rb +0 -37
  43. data/spec/html_safety_spec.rb +0 -48
  44. data/spec/javascript/escape_spec.rb +0 -34
  45. data/spec/javascript/unescape_spec.rb +0 -37
  46. data/spec/query/escape_spec.rb +0 -44
  47. data/spec/query/unescape_spec.rb +0 -46
  48. data/spec/rcov.opts +0 -3
  49. data/spec/spec_helper.rb +0 -5
  50. data/spec/uri/escape_spec.rb +0 -43
  51. data/spec/uri/unescape_spec.rb +0 -57
  52. data/spec/url/escape_spec.rb +0 -52
  53. data/spec/url/unescape_spec.rb +0 -57
@@ -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
@@ -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
@@ -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