fast_xs 0.7.3 → 0.8.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.
@@ -1,16 +1,27 @@
1
1
  all: test
2
2
  ext := fast_xs fast_xs_extra
3
- ruby = ruby
4
- DLEXT := $(shell $(ruby) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
3
+ RUBY = ruby
4
+ DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
5
5
 
6
6
  libs := $(addsuffix .$(DLEXT),$(addprefix lib/,$(ext)))
7
7
  build: $(libs)
8
8
 
9
+ makefiles = $(addsuffix /Makefile,$(addprefix ext/,$(ext)))
10
+
9
11
  %/Makefile: %/extconf.rb
10
- cd $(@D) && $(ruby) extconf.rb
11
- lib/fast_xs.$(DLEXT): ext/fast_xs/Makefile
12
- lib/fast_xs_extra.$(DLEXT): ext/fast_xs_extra/Makefile
13
- %.$(DLEXT):
12
+ cd $(@D) && $(RUBY) extconf.rb
13
+
14
+ deps := ext/fast_xs/Makefile $(wildcard ext/fast_xs/*.[ch])
15
+ extra_deps := ext/fast_xs_extra/Makefile $(wildcard ext/fast_xs_extra/*.[ch])
16
+
17
+ ext/fast_xs/fast_xs.$(DLEXT): $(deps)
18
+ $(MAKE) -C $(@D)
19
+ ext/fast_xs_extra/fast_xs_extra.$(DLEXT): $(extra_deps)
20
+ $(MAKE) -C $(@D)
21
+
22
+ lib/fast_xs.$(DLEXT): ext/fast_xs/fast_xs.$(DLEXT)
23
+ lib/fast_xs_extra.$(DLEXT): ext/fast_xs_extra/fast_xs_extra.$(DLEXT)
24
+ lib/%.$(DLEXT):
14
25
  $(MAKE) -C $(<D)
15
26
  install -m 644 $(<D)/$(@F) $@
16
27
  %/clean:
@@ -23,6 +34,6 @@ T := $(wildcard test/test_*.rb)
23
34
  test:
24
35
  $(MAKE) $(T)
25
36
  $(T): $(libs)
26
- $(ruby) -w -Ilib $@
37
+ $(RUBY) -w -Ilib $@
27
38
 
28
39
  .PHONY: test doc build all $(T)
@@ -1,3 +1,12 @@
1
+ === 0.8.0 / 2011-01-26
2
+
3
+ * preserve encoding of original string under Ruby 1.9
4
+ * avoid warnings when monkey patching
5
+ * internal cleanups
6
+
7
+ Browse gitweb for full history:
8
+ http://fast-xs.rubyforge.org/git?p=fast-xs.git
9
+
1
10
  === 0.7.3 / 2009-07-31
2
11
 
3
12
  * 1 bug fix:
@@ -1,8 +1,8 @@
1
1
  .gitignore
2
2
  GNUmakefile
3
- History.txt
3
+ History.rdoc
4
4
  Manifest.txt
5
- README.txt
5
+ README.rdoc
6
6
  Rakefile
7
7
  ext/fast_xs/extconf.rb
8
8
  ext/fast_xs/fast_xs.c
@@ -15,4 +15,6 @@ lib/fast_xs_monkey_patcher.rb
15
15
  setup.rb
16
16
  test/test_cgi_class_overrides.rb
17
17
  test/test_erb_util_module_overrides.rb
18
+ test/test_mongrel_overrides.rb
19
+ test/test_rack_util_overrides.rb
18
20
  test/test_xml_escaping.rb
@@ -50,7 +50,7 @@ Rubinius project.
50
50
 
51
51
  (The MIT License)
52
52
 
53
- Copyright (c) Eric Wong
53
+ Copyright (c) all contributors (see logs in git)
54
54
 
55
55
  Permission is hereby granted, free of charge, to any person obtaining
56
56
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,18 +1,21 @@
1
1
  require 'hoe'
2
- begin
3
- require 'rake/extensiontask'
4
- Rake::ExtensionTask.new('fast_xs')
5
- Rake::ExtensionTask.new('fast_xs_extra')
6
- rescue LoadError
7
- warn "rake-compiler not available, cross compiling disabled"
8
- end
9
-
10
- Hoe.spec('fast_xs') do
11
- self.version = '0.7.3'
12
- self.author = 'Eric Wong'
2
+ hoe = Hoe.spec('fast_xs') do
3
+ self.version = '0.8.0'
4
+ self.author = 'fast_xs hackers'
13
5
  self.email = 'fast-xs-general@rubyforge.org'
14
6
  self.url = 'http://fast-xs.rubyforge.org/'
7
+ self.history_file = 'History.rdoc'
8
+ self.readme_file = 'README.rdoc'
15
9
  self.remote_rdoc_dir = ''
16
10
  self.rubyforge_name = 'fast-xs'
17
11
  self.spec_extras = { :extensions => Dir.glob('ext/*/extconf.rb') }
18
12
  end
13
+
14
+ # optional rake-compiler support in case somebody needs to cross compile
15
+ begin
16
+ require 'rake/extensiontask'
17
+ Rake::ExtensionTask.new('fast_xs', hoe.spec)
18
+ Rake::ExtensionTask.new('fast_xs_extra', hoe.spec)
19
+ rescue LoadError
20
+ warn "rake-compiler not available, cross compiling disabled"
21
+ end
@@ -163,7 +163,7 @@ static VALUE fast_xs(VALUE self)
163
163
  s_len += bytes_for(n) - 1;
164
164
  }
165
165
 
166
- rv = rb_str_new(NULL, s_len);
166
+ rv = fast_xs_buf_new(self, s_len);
167
167
  c = RSTRING_PTR(rv);
168
168
 
169
169
  for (tmp = RARRAY_PTR(array), i = RARRAY_LEN(array); --i >= 0; tmp++)
@@ -12,3 +12,18 @@
12
12
  # define RARRAY_LEN(s) (RARRAY(s)->len)
13
13
  #endif
14
14
 
15
+ #ifdef HAVE_RUBY_ENCODING_H
16
+ #include <ruby/encoding.h>
17
+ static VALUE fast_xs_buf_new(VALUE orig, long len)
18
+ {
19
+ rb_encoding *enc = rb_enc_get(orig);
20
+ VALUE str = rb_str_new(NULL, len);
21
+
22
+ return rb_enc_associate(str, enc);
23
+ }
24
+ #else /* ! HAVE_RUBY_ENCODING_H */
25
+ static VALUE fast_xs_buf_new(VALUE orig, long len)
26
+ {
27
+ return rb_str_new(NULL, len);
28
+ }
29
+ #endif /* ! HAVE_RUBY_ENCODING_H */
@@ -4,6 +4,10 @@
4
4
  #include "fast_xs_type.h"
5
5
  #include "gcc.h"
6
6
 
7
+ #define APPEND_CONST(buf, x) do { \
8
+ buf = (char *)memcpy(buf, x, sizeof(x) - 1) + sizeof(x) - 1; \
9
+ } while (0)
10
+
7
11
  /*
8
12
  * This is coding agnostic, and works on each byte, so some multibyte
9
13
  * character sets may not be fully supported (but UTF-8 should be).
@@ -27,28 +31,22 @@ static VALUE fast_xs_html(VALUE self)
27
31
  new_len += (sizeof("&quot;") - 2);
28
32
  }
29
33
 
30
- rv = rb_str_new(NULL, new_len);
34
+ rv = fast_xs_buf_new(self, new_len);
31
35
  new_str = RSTRING_PTR(rv);
32
36
 
33
- #define append_const(buf, x) do { \
34
- buf = memcpy(buf, x, sizeof(x) - 1) + sizeof(x) - 1; \
35
- } while (0)
36
-
37
37
  for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
38
38
  if (unlikely(*s == '&'))
39
- append_const(new_str, "&amp;");
39
+ APPEND_CONST(new_str, "&amp;");
40
40
  else if (unlikely(*s == '<'))
41
- append_const(new_str, "&lt;");
41
+ APPEND_CONST(new_str, "&lt;");
42
42
  else if (unlikely(*s == '>'))
43
- append_const(new_str, "&gt;");
43
+ APPEND_CONST(new_str, "&gt;");
44
44
  else if (unlikely(*s == '"'))
45
- append_const(new_str, "&quot;");
45
+ APPEND_CONST(new_str, "&quot;");
46
46
  else
47
47
  *new_str++ = *s;
48
48
  }
49
49
 
50
- #undef append_const
51
-
52
50
  return rv;
53
51
  }
54
52
 
@@ -72,7 +70,7 @@ static inline VALUE _xs_uri_encode(VALUE self, const unsigned int space_to_plus)
72
70
  new_len += 2;
73
71
  }
74
72
 
75
- rv = rb_str_new(NULL, new_len);
73
+ rv = fast_xs_buf_new(self, new_len);
76
74
  new_str = RSTRING_PTR(rv);
77
75
 
78
76
  for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
@@ -132,7 +130,7 @@ static VALUE _uxs_uri(VALUE self, const unsigned int plus_to_space)
132
130
  }
133
131
  }
134
132
 
135
- rv = rb_str_new(NULL, new_len);
133
+ rv = fast_xs_buf_new(self, new_len);
136
134
  new_str = RSTRING_PTR(rv);
137
135
 
138
136
  for (s = RSTRING_PTR(self), i = RSTRING_LEN(self);
@@ -2,13 +2,22 @@ require 'fast_xs'
2
2
  require 'fast_xs_extra'
3
3
 
4
4
  class CGI # :nodoc:
5
- def CGI::escapeHTML(value); value.fast_xs_html; end
6
- def CGI::escape(value); value.fast_xs_cgi; end
7
- def CGI::unescape(value); value.fast_uxs_cgi; end
5
+ class << self
6
+ undef_method :escapeHTML
7
+ undef_method :escape
8
+ undef_method :unescape
9
+ def escapeHTML(value); value.fast_xs_html; end
10
+ def escape(value); value.fast_xs_cgi; end
11
+ def unescape(value); value.fast_uxs_cgi; end
12
+ end
8
13
  end if defined?(CGI)
9
14
 
10
15
  class ERB # :nodoc:
11
16
  module Util # :nodoc:
17
+ undef_method :html_escape
18
+ undef_method :h
19
+ undef_method :url_encode
20
+ undef_method :u
12
21
 
13
22
  def html_escape(value); value.to_s.fast_xs_html; end
14
23
  alias h html_escape
@@ -24,16 +33,22 @@ end if defined?(ERB::Util)
24
33
 
25
34
  module Mongrel # :nodoc:
26
35
  class HttpRequest # :nodoc:
27
- def self.unescape(s); s.fast_uxs_cgi; end
28
- def self.escape(s); s.to_s.fast_xs_cgi; end
36
+ class << self
37
+ undef_method :unescape
38
+ undef_method :escape
39
+ def unescape(s); s.fast_uxs_cgi; end
40
+ def escape(s); s.to_s.fast_xs_cgi; end
41
+ end
29
42
  end
30
43
  end if defined?(Mongrel::HttpRequest)
31
44
 
32
45
  module Rack # :nodoc:
33
46
  module Utils # :nodoc:
47
+ undef_method :unescape
34
48
  def unescape(s); s.fast_uxs_cgi; end
35
49
  module_function :unescape
36
50
 
51
+ undef_method :escape
37
52
  def escape(s); s.to_s.fast_xs_cgi; end
38
53
  module_function :escape
39
54
  end
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require 'test/unit'
2
3
  require 'cgi'
3
4
  require 'fast_xs_monkey_patcher'
@@ -56,6 +57,21 @@ class TestCgiClassOverrides < Test::Unit::TestCase
56
57
  end
57
58
  end
58
59
 
60
+ def test_default_encoding_preserved
61
+ amp = "&"
62
+ assert_equal Encoding::UTF_8, amp.encoding
63
+ res = CGI.escapeHTML(amp)
64
+ assert_equal "&amp;", res
65
+ assert_equal Encoding::UTF_8, res.encoding
66
+ end if defined?(Encoding)
59
67
 
68
+ def test_forced_encoding_preserved
69
+ amp = "&"
70
+ assert_nothing_raised {
71
+ amp.force_encoding Encoding::US_ASCII
72
+ }
73
+ res = CGI.escapeHTML(amp)
74
+ assert_equal "&amp;", res
75
+ assert_equal Encoding::US_ASCII, res.encoding
76
+ end if defined?(Encoding)
60
77
  end
61
-
@@ -33,6 +33,21 @@ class TestErbUtilModuleOverrides < Test::Unit::TestCase
33
33
  assert_equal 'H3LL0%20W0RLD', url_encode('H3LL0 W0RLD')
34
34
  end
35
35
 
36
+ def test_preserve_encoding
37
+ foo = "foo"
38
+ foo.force_encoding Encoding::US_ASCII
39
+ assert_equal Encoding::US_ASCII, url_encode(foo).encoding
40
+ assert_equal Encoding::US_ASCII, html_escape(foo).encoding
41
+ assert_equal Encoding::US_ASCII, u(foo).encoding
42
+ assert_equal Encoding::US_ASCII, h(foo).encoding
43
+
44
+ foo.force_encoding Encoding::BINARY
45
+ assert_equal Encoding::BINARY, url_encode(foo).encoding
46
+ assert_equal Encoding::BINARY, html_escape(foo).encoding
47
+ assert_equal Encoding::BINARY, u(foo).encoding
48
+ assert_equal Encoding::BINARY, h(foo).encoding
49
+ end if defined?(Encoding)
50
+
36
51
  def test_large_strings
37
52
  if ENV['LARGE_STRING_TEST']
38
53
  assert u('&' * (8192 * 1024))
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'mongrel'
3
+ $orig_escape = Mongrel::HttpRequest.method(:escape)
4
+ $orig_unescape = Mongrel::HttpRequest.method(:unescape)
5
+ rescue SyntaxError,LoadError => e
6
+ warn "skipping Mongrel test, Mongrel not available or broken under 1.9.2"
7
+ end
8
+
9
+ require 'test/unit'
10
+ require 'fast_xs_monkey_patcher'
11
+
12
+ class TestMongrelHttpOverrides < Test::Unit::TestCase
13
+ def test_escape
14
+ assert_equal "%2B", Mongrel::HttpRequest.escape("+")
15
+ end
16
+
17
+ def test_unescape
18
+ assert_equal "+", Mongrel::HttpRequest.unescape("%2B")
19
+ end
20
+ end if defined?(Mongrel::HttpRequest)
@@ -0,0 +1,43 @@
1
+ require 'rack'
2
+ $orig_escape = Rack::Utils.method(:escape)
3
+ $orig_unescape = Rack::Utils.method(:unescape)
4
+ require 'test/unit'
5
+ require 'fast_xs_monkey_patcher'
6
+
7
+ # copied and translated to Test::Unit from test/spec_utils.rb in rack
8
+
9
+ class TestRackUtilModuleOverrides < Test::Unit::TestCase
10
+
11
+ def test_overidden
12
+ assert $orig_escape != Rack::Utils.method(:escape)
13
+ assert $orig_unescape != Rack::Utils.method(:unescape)
14
+ end
15
+
16
+ def test_escape_html_predefined
17
+ assert_equal "fo%3Co%3Ebar", Rack::Utils.escape("fo<o>bar")
18
+ assert_equal "a+space", Rack::Utils.escape("a space")
19
+ assert_equal "q1%212%22%27w%245%267%2Fz8%29%3F%5C",
20
+ Rack::Utils.escape("q1!2\"'w$5&7/z8)?\\")
21
+
22
+ matz_name = # Matsumoto
23
+ "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0]
24
+ matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
25
+ assert_equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8',
26
+ Rack::Utils.escape(matz_name)
27
+
28
+ matz_name_sep = # Matsu moto
29
+ "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0]
30
+ matz_name_sep.respond_to?(:force_encoding) and
31
+ matz_name_sep.force_encoding("UTF-8")
32
+ assert_equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8',
33
+ Rack::Utils.escape(matz_name_sep)
34
+ end
35
+
36
+ def test_unescape
37
+ assert_equal "fo<o>bar", Rack::Utils.unescape("fo%3Co%3Ebar")
38
+ assert_equal "a space", Rack::Utils.unescape("a+space")
39
+ assert_equal "a space", Rack::Utils.unescape("a%20space")
40
+ assert_equal "q1!2\"'w$5&7/z8)?\\",
41
+ Rack::Utils.unescape("q1%212%22%27w%245%267%2Fz8%29%3F%5C")
42
+ end
43
+ end
@@ -37,6 +37,30 @@ class TestXmlEscaping < Test::Unit::TestCase
37
37
  assert_equal '&#169;', "\xC2\xA9".fast_xs # copy
38
38
  end
39
39
 
40
+ def test_iso_8859_1_encoding_preserved
41
+ copyright = "\xA9"
42
+ copyright.force_encoding Encoding::ISO_8859_1
43
+ assert_equal '&#169;', copyright.fast_xs
44
+ assert copyright.fast_xs.valid_encoding?
45
+ assert_equal Encoding::ISO_8859_1, copyright.fast_xs.encoding
46
+ end if defined?(Encoding)
47
+
48
+ def test_win_1252_encoding_preserved
49
+ euro = "\x80"
50
+ euro.force_encoding Encoding::CP1252
51
+ assert_equal '&#8364;', euro.fast_xs
52
+ assert euro.fast_xs.valid_encoding?
53
+ assert_equal Encoding::CP1252, euro.fast_xs.encoding
54
+ end if defined?(Encoding)
55
+
56
+ def test_utf8_encoding_preserved
57
+ copy = "\xC2\xA9"
58
+ copy.force_encoding Encoding::UTF_8
59
+ assert_equal '&#169;', copy.fast_xs
60
+ assert_equal Encoding::UTF_8, copy.fast_xs.encoding
61
+ assert copy.fast_xs.valid_encoding?
62
+ end if defined?(Encoding)
63
+
40
64
  def test_large_document
41
65
  if ENV['LARGE_STRING_TEST']
42
66
  assert(('&' * (8192 * 1024)).fast_xs)
metadata CHANGED
@@ -1,27 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_xs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
5
11
  platform: ruby
6
12
  authors:
7
- - Eric Wong
13
+ - fast_xs hackers
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-07-31 00:00:00 -07:00
18
+ date: 2011-01-26 00:00:00 +00:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: hoe
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: 2.3.2
24
- version:
29
+ hash: 47
30
+ segments:
31
+ - 2
32
+ - 8
33
+ - 0
34
+ version: 2.8.0
35
+ type: :development
36
+ version_requirements: *id001
25
37
  description: |-
26
38
  fast_xs provides C extensions for escaping text.
27
39
 
@@ -49,15 +61,13 @@ extensions:
49
61
  - ext/fast_xs/extconf.rb
50
62
  - ext/fast_xs_extra/extconf.rb
51
63
  extra_rdoc_files:
52
- - History.txt
53
64
  - Manifest.txt
54
- - README.txt
55
65
  files:
56
66
  - .gitignore
57
67
  - GNUmakefile
58
- - History.txt
68
+ - History.rdoc
59
69
  - Manifest.txt
60
- - README.txt
70
+ - README.rdoc
61
71
  - Rakefile
62
72
  - ext/fast_xs/extconf.rb
63
73
  - ext/fast_xs/fast_xs.c
@@ -70,6 +80,8 @@ files:
70
80
  - setup.rb
71
81
  - test/test_cgi_class_overrides.rb
72
82
  - test/test_erb_util_module_overrides.rb
83
+ - test/test_mongrel_overrides.rb
84
+ - test/test_rack_util_overrides.rb
73
85
  - test/test_xml_escaping.rb
74
86
  has_rdoc: true
75
87
  homepage: http://fast-xs.rubyforge.org/
@@ -78,30 +90,37 @@ licenses: []
78
90
  post_install_message:
79
91
  rdoc_options:
80
92
  - --main
81
- - README.txt
93
+ - README.rdoc
82
94
  require_paths:
83
95
  - lib
84
- - ext
85
96
  required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ">="
88
100
  - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
89
104
  version: "0"
90
- version:
91
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
92
107
  requirements:
93
108
  - - ">="
94
109
  - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
95
113
  version: "0"
96
- version:
97
114
  requirements: []
98
115
 
99
116
  rubyforge_project: fast-xs
100
- rubygems_version: 1.3.5
117
+ rubygems_version: 1.3.7
101
118
  signing_key:
102
119
  specification_version: 3
103
120
  summary: fast_xs provides C extensions for escaping text
104
121
  test_files:
105
- - test/test_cgi_class_overrides.rb
106
122
  - test/test_xml_escaping.rb
123
+ - test/test_mongrel_overrides.rb
124
+ - test/test_rack_util_overrides.rb
125
+ - test/test_cgi_class_overrides.rb
107
126
  - test/test_erb_util_module_overrides.rb