Skip to content

Commit 7cdbe51

Browse files
committed
[LH345] stripping trailing slashes from page paths
1 parent 8fb5db3 commit 7cdbe51

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/models/page.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Page < ActiveRecord::Base
6161

6262
has_many :tasks
6363

64-
before_validation :append_leading_slash_to_path
64+
before_validation :append_leading_slash_to_path, :remove_trailing_slash_from_path
6565
before_destroy :delete_connectors
6666

6767
validates_presence_of :name, :path
@@ -218,6 +218,12 @@ def append_leading_slash_to_path
218218
self.path = "/#{path}"
219219
end
220220
end
221+
222+
# remove trailing slash, unless the path is only a slash. uses capture and
223+
# substition because ruby regex engine does not support lookbehind
224+
def remove_trailing_slash_from_path
225+
self.path.sub!(/(.+)\/+$/, '\1')
226+
end
221227

222228
def path_not_reserved
223229
if Cms.reserved_paths.include?(path)

0 commit comments

Comments
 (0)