Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes #8631 request post? detection should remain unaffected by local inflections such as POS for Point Of Sale #8632

Merged
merged 1 commit into from

2 participants

@asanghi

request post? detection should remain unaffected by local inflections such as POS for PointOfSale

@pixeltrix pixeltrix was assigned
@asanghi

@pixeltrix Andrew, just a gentle nudge to address this please? I understand that underscore is used in a number of places but this particular use is working on a very limited set of inputs to underscore. What do you think?

@pixeltrix
Owner

@asanghi this needs to be against master doesn't it - problem appears there as well

@asanghi
@pixeltrix
Owner

Sorry, I forgot you mentioned that in #8631. I actually prefer the fix in 872d8c3 - can you update this PR to match that and squash the commits. Once that's done I'll merge it.

@asanghi

@pixeltrix squashed with solution from master and added changelog entry and test.

actionpack/lib/action_dispatch/http/request.rb
@@ -56,7 +56,13 @@ def key?(key)
RFC5789 = %w(PATCH)
HTTP_METHODS = RFC2616 + RFC2518 + RFC3253 + RFC3648 + RFC3744 + RFC5323 + RFC5789
- HTTP_METHOD_LOOKUP = Hash.new { |h, m| h[m] = m.underscore.to_sym if HTTP_METHODS.include?(m) }
+ HTTP_METHOD_LOOKUP = {}
+
+ # Populate the HTTP method lookup cache
+ HTTP_METHODS.each do |method|
+ HTTP_METHOD_LOOKUP[method] = method.underscore.to_sym
+ HTTP_METHOD_LOOKUP[method.to_sym] = method.underscore.to_sym
@pixeltrix Owner

Why the double assignment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@asanghi

Good catch @pixeltrix . I was mucking around with tests earlier and it was left behind. Removed and squashed again.

@pixeltrix pixeltrix merged commit d3dcb4b into from
@pixeltrix
Owner

Thanks @arunagw - I think we should add the test to master as well. Can you create a PR?

@asanghi

I'm sure you meant @asanghi and I will. :)

@pixeltrix
Owner

Yes, the autocomplete jumped to the wrong one and I didn't notice - thanks.

@asanghi

@pixeltrix .. see #8963 for pull on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 16, 2013
  1. @asanghi
This page is out of date. Refresh to see the latest.
View
5 actionpack/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 3.2.12 (unreleased) ##
+* Eagerly populate the http method loookup cache so local project inflections do
+ not interfere with use of underscore method ( and we don't need locks )
+
+ *Aditya Sanghi*
+
* `BestStandardsSupport` no longer duplicates `X-UA-Compatible` values on
each request to prevent header size from blowing up.
View
7 actionpack/lib/action_dispatch/http/request.rb
@@ -56,7 +56,12 @@ def key?(key)
RFC5789 = %w(PATCH)
HTTP_METHODS = RFC2616 + RFC2518 + RFC3253 + RFC3648 + RFC3744 + RFC5323 + RFC5789
- HTTP_METHOD_LOOKUP = Hash.new { |h, m| h[m] = m.underscore.to_sym if HTTP_METHODS.include?(m) }
+ HTTP_METHOD_LOOKUP = {}
+
+ # Populate the HTTP method lookup cache
+ HTTP_METHODS.each do |method|
+ HTTP_METHOD_LOOKUP[method] = method.underscore.to_sym
+ end
# Returns the HTTP \method that the application should see.
# In the case where the \method was overridden by a middleware
View
21 actionpack/test/dispatch/request_test.rb
@@ -371,6 +371,27 @@ def url_for(options = {})
assert request.put?
end
+ test "post uneffected by local inflections" do
+ existing_acrnoyms = ActiveSupport::Inflector.inflections.acronyms.dup
+ existing_acrnoym_regex = ActiveSupport::Inflector.inflections.acronym_regex.dup
+ begin
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym "POS"
+ end
+ assert_equal "pos_t", "POST".underscore
+ request = stub_request "REQUEST_METHOD" => "POST"
+ assert_equal :post, ActionDispatch::Request::HTTP_METHOD_LOOKUP["POST"]
+ assert_equal :post, request.method_symbol
+ assert request.post?
+ ensure
+ # Reset original acronym set
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.send(:instance_variable_set,"@acronyms",existing_acrnoyms)
+ inflect.send(:instance_variable_set,"@acronym_regex",existing_acrnoym_regex)
+ end
+ end
+ end
+
test "xml format" do
request = stub_request
request.expects(:parameters).at_least_once.returns({ :format => 'xml' })
Something went wrong with that request. Please try again.