lib/trac-wiki/parser.rb in trac-wiki-0.3.18 vs lib/trac-wiki/parser.rb in trac-wiki-0.3.19
- old
+ new
@@ -62,10 +62,13 @@
# url base for links
attr_writer :base
+ # url base for /links
+ attr_writer :root
+
# Disable url escaping for local links
# Escaping: [[/Test]] --> %2FTest
# No escaping: [[/Test]] --> Test
attr_writer :no_escape
def no_escape?; @no_escape; end
@@ -138,12 +141,14 @@
@allowed_schemes = %w(http https ftp ftps)
macro_commands = options.delete :macro_commands
@macro_commands.merge! macro_commands if ! macro_commands.nil?
@no_escape = nil
@base = ''
+ @root = ''
options.each_pair {|k,v| send("#{k}=", v) }
@base += '/' if !@base.empty? && @base[-1] != '/'
+ @root += '/' if @root.empty? || @root[-1] != '/'
end
def text(text)
@text = text
return self
@@ -314,12 +319,18 @@
# make_local_link("Wikipedia:Bread") #=> "http://en.wikipedia.org/wiki/Bread"
def make_local_link(link) #:doc:
# FIXME: xss when no_escape
link, anch = link.split(/#/, 2)
if no_escape?
- return "#{@base}#{link}" if ! anch
+ prefix = @base
+ if link =~ /^\/(.*)/
+ link = $1
+ prefix = @root
+ end
+
+ return "#{prefix}#{link}" if ! anch
return "##{anch}" if link == ''
- return "#{@base}#{link}##{anch}"
+ return "#{prefix}#{link}##{anch}"
end
return "#{@base}#{escape_url(link)}" if ! anch
return "##{escape_url(anch)}" if link == ''
"#{@base}#{escape_url(link)}##{escape_url(anch)}"
end