Skip to content
This repository
Browse code

Merge pull request #9564 from robertomiranda/useless_gsub

change useless gsub to tr
  • Loading branch information...
commit 588f267e71083928ee8b6375a444fb674dad8fcf 2 parents 09d1fb2 + 3bf961d
Guillermo Iguaran authored March 05, 2013
2  actionpack/lib/abstract_controller/translation.rb
@@ -11,7 +11,7 @@ module Translation
11 11
     def translate(*args)
12 12
       key = args.first
13 13
       if key.is_a?(String) && (key[0] == '.')
14  
-        key = "#{ controller_path.gsub('/', '.') }.#{ action_name }#{ key }"
  14
+        key = "#{ controller_path.tr('/', '.') }.#{ action_name }#{ key }"
15 15
         args[0] = key
16 16
       end
17 17
 
4  actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
@@ -10,7 +10,7 @@
10 10
   clean_params.delete("action")
11 11
   clean_params.delete("controller")
12 12
 
13  
-  request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
  13
+  request_dump = clean_params.empty? ? 'None' : clean_params.inspect.tr(',', ",\n")
14 14
 
15 15
   def debug_hash(object)
16 16
     object.to_hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
@@ -31,4 +31,4 @@
31 31
 </div>
32 32
 
33 33
 <h2 style="margin-top: 30px">Response</h2>
34  
-<p><b>Headers</b>:</p> <pre><%= defined?(@response) ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre>
  34
+<p><b>Headers</b>:</p> <pre><%= defined?(@response) ? @response.headers.inspect.tr(',', ",\n") : 'None' %></pre>
2  actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
@@ -8,7 +8,7 @@
8 8
       <h2>Failure reasons:</h2>
9 9
       <ol>
10 10
       <% @exception.failures.each do |route, reason| %>
11  
-        <li><code><%= route.inspect.gsub('\\', '') %></code> failed because <%= reason.downcase %></li>
  11
+        <li><code><%= route.inspect.delete('\\') %></code> failed because <%= reason.downcase %></li>
12 12
       <% end %>
13 13
       </ol>
14 14
     </p>
2  actionpack/lib/action_view/helpers/debug_helper.rb
@@ -28,7 +28,7 @@ module DebugHelper
28 28
       #   </pre>
29 29
       def debug(object)
30 30
         Marshal::dump(object)
31  
-        object = ERB::Util.html_escape(object.to_yaml).gsub("  ", "&nbsp; ").html_safe
  31
+        object = ERB::Util.html_escape(object.to_yaml).tr("  ", "&nbsp; ").html_safe
32 32
         content_tag(:pre, object, :class => "debug_dump")
33 33
       rescue Exception  # errors from Marshal or YAML
34 34
         # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback

4 notes on commit 588f267

Tee Parham

The same problem with tr not working with longer replacement strings exists on lines 13 & 34 of _request_and_response. The \n will be ignored:

> "a,b".tr(',', ",\n")
 => "a,b"

588f267#L1R13
588f267#L1R34

Roberto Miranda

@teeparham ok I'm revert this to use again gsub

Roberto Miranda

Fixed on #9586

Please sign in to comment.
Something went wrong with that request. Please try again.