ensure filename has an allowed extension

This commit is contained in:
Tom Preston-Werner
2010-04-08 16:31:28 -07:00
parent 3ff115048d
commit a328e15dc3
2 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -18,6 +18,6 @@ module Gollum
# #
# Returns the String canonical name. # Returns the String canonical name.
def self.canonical_name(name) def self.canonical_name(name)
name.gsub(/ /, '-').sub(/\.(.+?)$/, '') name.gsub(/ /, '-')
end end
end end
+10 -4
View File
@@ -1,5 +1,7 @@
module Gollum module Gollum
class Page class Page
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|re?st(\.txt)?|asciidoc|pod|\d)$/
attr_accessor :wiki, :data attr_accessor :wiki, :data
# Initialize a page. # Initialize a page.
@@ -68,12 +70,16 @@ module Gollum
# Compare the canonicalized versions of the two names. # Compare the canonicalized versions of the two names.
# #
# name1 - A human or canonical String page name. # name - The human or canonical String page name.
# name2 - A human or canonical String page name. # filename - the String filename on disk (including extension).
# #
# Returns a Boolean. # Returns a Boolean.
def page_match(name1, name2) def page_match(name, filename)
Gollum.canonical_name(name1) == Gollum.canonical_name(name2) if filename =~ VALID_PAGE_RE
Gollum.canonical_name(name) == Gollum.canonical_name($1)
else
false
end
end end
end end
end end