Skip to content

Commit

Permalink
[LH345] stripping trailing slashes from page paths
Browse files Browse the repository at this point in the history
  • Loading branch information
k1mmeh committed Jul 5, 2010
1 parent 8fb5db3 commit 7cdbe51
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/page.rb
Expand Up @@ -61,7 +61,7 @@ class Page < ActiveRecord::Base

has_many :tasks

before_validation :append_leading_slash_to_path
before_validation :append_leading_slash_to_path, :remove_trailing_slash_from_path
before_destroy :delete_connectors

validates_presence_of :name, :path
Expand Down Expand Up @@ -218,6 +218,12 @@ def append_leading_slash_to_path
self.path = "/#{path}"
end
end

# remove trailing slash, unless the path is only a slash. uses capture and
# substition because ruby regex engine does not support lookbehind
def remove_trailing_slash_from_path
self.path.sub!(/(.+)\/+$/, '\1')
end

def path_not_reserved
if Cms.reserved_paths.include?(path)
Expand Down

0 comments on commit 7cdbe51

Please sign in to comment.