trac-wiki 0.3.18 → 0.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,9 @@ module TracWiki
64
64
  # url base for links
65
65
  attr_writer :base
66
66
 
67
+ # url base for /links
68
+ attr_writer :root
69
+
67
70
  # Disable url escaping for local links
68
71
  # Escaping: [[/Test]] --> %2FTest
69
72
  # No escaping: [[/Test]] --> Test
@@ -140,8 +143,10 @@ module TracWiki
140
143
  @macro_commands.merge! macro_commands if ! macro_commands.nil?
141
144
  @no_escape = nil
142
145
  @base = ''
146
+ @root = ''
143
147
  options.each_pair {|k,v| send("#{k}=", v) }
144
148
  @base += '/' if !@base.empty? && @base[-1] != '/'
149
+ @root += '/' if @root.empty? || @root[-1] != '/'
145
150
  end
146
151
 
147
152
  def text(text)
@@ -316,9 +321,15 @@ module TracWiki
316
321
  # FIXME: xss when no_escape
317
322
  link, anch = link.split(/#/, 2)
318
323
  if no_escape?
319
- return "#{@base}#{link}" if ! anch
324
+ prefix = @base
325
+ if link =~ /^\/(.*)/
326
+ link = $1
327
+ prefix = @root
328
+ end
329
+
330
+ return "#{prefix}#{link}" if ! anch
320
331
  return "##{anch}" if link == ''
321
- return "#{@base}#{link}##{anch}"
332
+ return "#{prefix}#{link}##{anch}"
322
333
  end
323
334
  return "#{@base}#{escape_url(link)}" if ! anch
324
335
  return "##{escape_url(anch)}" if link == ''
@@ -1,3 +1,3 @@
1
1
  module TracWiki
2
- VERSION = '0.3.18'
2
+ VERSION = '0.3.19'
3
3
  end
data/test/parser_test.rb CHANGED
@@ -275,6 +275,14 @@ describe TracWiki::Parser do
275
275
  tc "<p><a href=\"link#link\">link#link</a></p>\n", "[[link#link]]"
276
276
  tc "<p><a href=\"#link\">#link</a></p>\n", "[[#link]]"
277
277
 
278
+ tc "<p><a href=\"BASE/link\">link</a></p>\n", "[[link]]", base: 'BASE', root: 'ROOT', no_escape: true
279
+ tc "<p><a href=\"ROOT/link\">/link</a></p>\n", "[[/link]]", base: 'BASE', root: 'ROOT', no_escape: true
280
+ tc "<p><a href=\"/link\">/link</a></p>\n", "[[/link]]", base: 'BASE', no_escape: true
281
+
282
+ tc "<p><a href=\"BASE/link\">bla</a></p>\n", "[[link | bla ]]", base: 'BASE', root: 'ROOT', no_escape: true
283
+ tc "<p><a href=\"ROOT/link\">bla</a></p>\n", "[[/link | bla ]]", base: 'BASE', root: 'ROOT', no_escape: true
284
+ tc "<p><a href=\"/link\">bla</a></p>\n", "[[/link | bla]]", base: 'BASE', no_escape: true
285
+
278
286
  # Links can appear in paragraphs (i.e. inline item)
279
287
  tc "<p>Hello, <a href=\"world\">world</a></p>\n", "Hello, [[world]]"
280
288
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trac-wiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.18
4
+ version: 0.3.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-03 00:00:00.000000000 Z
12
+ date: 2014-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon