Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11337 (closed defect: fixed)

Opened 5 months ago

Last modified 5 months ago

[PATCH][TINY] Routing normalize_paths bug

Reported by: veejar Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: routing patch tiny
Cc:

Description

=================================================== actionpack-2.0.2/lib/action_controller/routing.rb ===================================================

def "normalize_paths" in ActionController::Rounting doesn't work good. Example:

paths = ["/test/my.folder/.subfolder1/../.subfolder2"]
# result of "normalize_paths( paths)":
["/test/my.folder/..subfolder2"]

# This result is wrong.

# Right result:
["/test/my.folder/.subfolder2"]

Attachments

normalize_path_fix.diff (2.7 kB) - added by cavalle on 03/20/08 21:53:42.

Change History

(in reply to: ↑ description ) 03/12/08 16:25:56 changed by veejar

I thing that right code is:

      def normalize_paths(paths)
        # do the hokey-pokey of path normalization...
        paths = paths.collect do |path|
          path = path.
            gsub("//", "/").           # replace double / chars with a single
            gsub("\\\\", "\\").        # replace double \ chars with a single
            gsub(%r{(.)[\\/]$}, '\1')  # drop final / or \ if path ends with it

          # eliminate .. paths where possible
          re = %r{[^/\\]+[/\\]\.\.[/\\]}
          path.gsub!(re, "") while path.match(re)
          path
        end

03/20/08 21:53:42 changed by cavalle

  • attachment normalize_path_fix.diff added.

03/20/08 21:55:02 changed by cavalle

  • keywords changed from routing to routing patch tiny.
  • summary changed from Routing normalize_paths bug to [PATCH][TINY] Routing normalize_paths bug.

03/20/08 22:07:10 changed by cavalle

Tests and patch attached

03/21/08 18:17:47 changed by david.calavera

+1

03/21/08 22:44:07 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [9069]) Fix an edge case with extra periods in Routing.normalize_paths. Closes #11337 [cavalle, veejar]

03/21/08 22:46:54 changed by bitsweat

(In [9070]) Merge [9069] from trunk: Fix an edge case with extra periods in Routing.normalize_paths. References #11337.