Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Made changes for easier ruby 1.8 integration #384

Closed
wants to merge 2 commits into from

2 participants

@joshreed

Hi, I needed to make these changes for a project I'm working on (a rails 3.0.3 project that had some strong gem dependencies that didn't allow me to update rack to version >= 1.4). And the entire project was created for ruby 1.8.7, and upgrading to 1.9+ is not an option at this point--though it is planned for the future when time permits.

I feel that this situation may be somewhat common, and therefore these changes allow Tire to work properly without as many dependency headaches. It's up to you if you want to include these changes, but by making these changes it certainly made my life easier!

@karmi
Owner

@joshreed So, basically, you're suggesting to drop the rack/backports/uri/common_18 patch from Rack (so we don't have to require the 1.4 version) and drop it in directly? I'm not against it, if that solves the problem, just wanna make sure I understand the picture...

@joshreed

@karmi Yep, that's exactly correct. Ultimately it creates less gem dependencies that could be annoying for those who have code still using ruby 1.8.7. Like I said, it's completely up to you if you want to include it, it just solved my problem and I thought it could be helpful for others as well.

Even though it could be considered slightly on the non-DRY side, to me the decrease in dependencies is worth it. Plus, since it is a back-port of ruby 1.9 functionality anyway, it doesn't seem bad to me for Tire to include its own copy of the necessary back-ported functionality.

I only tested it with Rack 1.2+, and I didn't completely go through the Tire code to see if you use Rack for anything else (besides this back-ported functionality), but it may be possible to completely drop the dependency on Rack by making this change, which could be even better.

Anyway, let me know if you have any other questions, I'd be glad to help.

@karmi karmi closed this in c772948
@karmi
Owner

OK, merged, fixed, pushed. Rack wasn't indeed used for anything else, just the URI escaping.

@NOX73 NOX73 referenced this pull request from a commit in NOX73/tire
@joshreed joshreed Changed the URI escape/unescape compatibility patch to not require Rack
Originally by @joshreed, cleanup by @karmi.

Closes #384.
8a56d63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 19, 2012
  1. @joshreed

    Updated ruby 1.8 requirements so that it no longer is necessary to ha…

    joshreed authored
    …ve a specific version of rack.
  2. @joshreed
This page is out of date. Refresh to see the latest.
Showing with 66 additions and 6 deletions.
  1. +65 −5 lib/tire/rubyext/ruby_1_8.rb
  2. +1 −1  tire.gemspec
View
70 lib/tire/rubyext/ruby_1_8.rb
@@ -1,7 +1,67 @@
require 'rubygems'
-# Require URI escape/unescape compatibility layer from Rack
-#
-# See <http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI.html#method-c-encode_www_form_component>
-#
-require 'rack/backports/uri/common_18'
+# Use additional URI. This is different from the karmi/tire in that we are not requiring specific RACK versions.
+# This allows for compatibility with older versions of Rails.
+
+module URI
+ TBLENCWWWCOMP_ = {} # :nodoc:
+ TBLDECWWWCOMP_ = {} # :nodoc:
+
+ # Encode given +s+ to URL-encoded form data.
+ #
+ # This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
+ # (ASCII space) to + and converts others to %XX.
+ #
+ # This is an implementation of
+ # http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
+ #
+ # See URI.decode_www_form_component, URI.encode_www_form
+ def self.encode_www_form_component(s)
+ str = s.to_s
+ if RUBY_VERSION < "1.9" && $KCODE =~ /u/i
+ str.gsub(/([^ a-zA-Z0-9_.-]+)/) do
+ '%' + $1.unpack('H2' * Rack::Utils.bytesize($1)).join('%').upcase
+ end.tr(' ', '+')
+ else
+ if TBLENCWWWCOMP_.empty?
+ tbl = {}
+ 256.times do |i|
+ tbl[i.chr] = '%%%02X' % i
+ end
+ tbl[' '] = '+'
+ begin
+ TBLENCWWWCOMP_.replace(tbl)
+ TBLENCWWWCOMP_.freeze
+ rescue
+ end
+ end
+ str.gsub(/[^*\-.0-9A-Z_a-z]/) {|m| TBLENCWWWCOMP_[m]}
+ end
+ end
+
+ # Decode given +str+ of URL-encoded form data.
+ #
+ # This decods + to SP.
+ #
+ # See URI.encode_www_form_component, URI.decode_www_form
+ def self.decode_www_form_component(str, enc=nil)
+ if TBLDECWWWCOMP_.empty?
+ tbl = {}
+ 256.times do |i|
+ h, l = i>>4, i&15
+ tbl['%%%X%X' % [h, l]] = i.chr
+ tbl['%%%x%X' % [h, l]] = i.chr
+ tbl['%%%X%x' % [h, l]] = i.chr
+ tbl['%%%x%x' % [h, l]] = i.chr
+ end
+ tbl['+'] = ' '
+ begin
+ TBLDECWWWCOMP_.replace(tbl)
+ TBLDECWWWCOMP_.freeze
+ rescue
+ end
+ end
+ raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str
+ str.gsub(/\+|%[0-9a-fA-F]{2}/) {|m| TBLDECWWWCOMP_[m]}
+ end
+end
View
2  tire.gemspec
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
s.add_dependency "multi_json", "~> 1.0"
s.add_dependency "activemodel", ">= 3.0"
s.add_dependency "hashr", "~> 0.0.19"
- s.add_dependency "rack", ">= 1.4" if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
+ s.add_dependency "rack", ">= 1.2" if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9' # No longer must be >= 1.4
# = Development dependencies
#
Something went wrong with that request. Please try again.