gollum 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gollum might be problematic. Click here for more details.

@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.required_ruby_version = ">= 1.8.7"
6
6
 
7
7
  s.name = 'gollum'
8
- s.version = '2.1.6'
9
- s.date = '2012-08-23'
8
+ s.version = '2.1.7'
9
+ s.date = '2012-08-25'
10
10
  s.rubyforge_project = 'gollum'
11
11
 
12
12
  s.summary = "A simple, Git-powered wiki."
@@ -22,7 +22,7 @@ require File.expand_path('../gollum/tex', __FILE__)
22
22
  require File.expand_path('../gollum/web_sequence_diagram', __FILE__)
23
23
 
24
24
  module Gollum
25
- VERSION = '2.1.6'
25
+ VERSION = '2.1.7'
26
26
 
27
27
  def self.assets_path
28
28
  ::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__))
@@ -90,19 +90,26 @@ module Precious
90
90
  redirect File.join(settings.wiki_options[:base_path].to_s, 'Home')
91
91
  end
92
92
 
93
+ # Removes all slashes from the start of string.
94
+ def clean_url url
95
+ return url if url.nil?
96
+ url.gsub('%2F','/').gsub(/^\/+/,'')
97
+ end
98
+
93
99
  # path is set to name if path is nil.
94
100
  # if path is 'a/b' and a and b are dirs, then
95
101
  # path must have a trailing slash 'a/b/' or
96
102
  # extract_path will trim path to 'a'
97
103
  # name, path, version
98
- def wiki_page( name, path = nil, version = nil)
104
+ def wiki_page(name, path = nil, version = nil, exact = true)
99
105
  path = name if path.nil?
100
106
  name = extract_name(name)
101
107
  path = extract_path(path)
108
+ path = '/' if exact && path.nil?
102
109
 
103
110
  wiki = wiki_new
104
111
 
105
- OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, version),
112
+ OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, exact, version),
106
113
  :name => name, :path => path)
107
114
  end
108
115
 
@@ -141,14 +148,14 @@ module Precious
141
148
  end
142
149
 
143
150
  post '/edit/*' do
144
- wikip = wiki_page(CGI.unescape(params[:page]), sanitize_empty_params(params[:path]))
145
- path = wikip.path
146
- wiki = wikip.wiki
147
- page = wikip.page
148
- rename = params[:rename].to_url if params[:rename]
149
- name = rename || page.name
150
- committer = Gollum::Committer.new(wiki, commit_message)
151
- commit = {:committer => committer}
151
+ path = '/' + clean_url(sanitize_empty_params(params[:path])).to_s
152
+ page_name = CGI.unescape(params[:page])
153
+ wiki = wiki_new
154
+ page = wiki.paged(page_name, path, exact = true)
155
+ rename = params[:rename].to_url if params[:rename]
156
+ name = rename || page.name
157
+ committer = Gollum::Committer.new(wiki, commit_message)
158
+ commit = {:committer => committer}
152
159
 
153
160
  update_wiki_page(wiki, page, params[:content], commit, name, params[:format])
154
161
  update_wiki_page(wiki, page.header, params[:header], commit) if params[:header]
@@ -187,6 +194,7 @@ module Precious
187
194
  post '/create' do
188
195
  name = params[:page].to_url
189
196
  path = sanitize_empty_params(params[:path])
197
+ path = '' if path.nil?
190
198
  format = params[:format].intern
191
199
 
192
200
  # write_page is not directory aware so use wiki_options to emulate dir support.
@@ -195,8 +203,7 @@ module Precious
195
203
 
196
204
  begin
197
205
  wiki.write_page(name, format, params[:content], commit_message)
198
- page = wiki.page(name)
199
- redirect to("/#{page.escaped_url_path}") unless page.nil?
206
+ redirect to("/#{clean_url(CGI.escape(::File.join(path,name)))}")
200
207
  rescue Gollum::DuplicatePageError => e
201
208
  @message = "Duplicate page: #{e.message}"
202
209
  mustache :error
@@ -341,7 +348,9 @@ module Precious
341
348
  path = extract_path(fullpath)
342
349
  wiki = wiki_new
343
350
 
344
- if page = wiki.paged(name, path)
351
+ path = '/' if path.nil?
352
+
353
+ if page = wiki.paged(name, path, exact = true)
345
354
  @page = page
346
355
  @name = name
347
356
  @editable = true
@@ -354,7 +363,7 @@ module Precious
354
363
  file.raw_data
355
364
  else
356
365
  page_path = [path, name].compact.join('/')
357
- redirect to("/create/#{encodeURIComponent(page_path).gsub('%2F','/')}")
366
+ redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
358
367
  end
359
368
  end
360
369
 
@@ -99,13 +99,21 @@ $.save = function( commitMessage ) {
99
99
  var msg = defaultCommitMessage();
100
100
  var newLocation = baseUrl;
101
101
 
102
+ function clean( str ) {
103
+ return str.replace(/^\/+/g, '/');
104
+ }
105
+
102
106
  // 'a%2Fb' => a/b
103
- if (pathName) {
104
- newLocation += '/' + unescape(pathName);
107
+ if ( pathName ) {
108
+ pathName = unescape( pathName );
109
+ newLocation += '/' + pathName;
105
110
  pathName = pathName + '/'; // pathName must end with /
111
+
112
+ pathName = clean( pathName );
106
113
  }
107
114
 
108
115
  newLocation += '/' + pageName;
116
+ newLocation = clean( newLocation );
109
117
 
110
118
  // if &create=true then handle create instead of edit.
111
119
  if ( create ) {
@@ -228,7 +228,7 @@ module Gollum
228
228
  if is_preformatted?(data, id)
229
229
  data.gsub!(id, "[[#{tag}]]")
230
230
  else
231
- data.gsub!(id, process_tag(tag))
231
+ data.gsub!(id, process_tag(tag).gsub('%2F', '/'))
232
232
  end
233
233
  end
234
234
  data
@@ -441,13 +441,23 @@ module Gollum
441
441
  # Find a page from a given cname. If the page has an anchor (#) and has
442
442
  # no match, strip the anchor and try again.
443
443
  #
444
- # cname - The String canonical page name.
444
+ # cname - The String canonical page name including path.
445
445
  #
446
446
  # Returns a Gollum::Page instance if a page is found, or an Array of
447
447
  # [Gollum::Page, String extra] if a page without the extra anchor data
448
448
  # is found.
449
449
  def find_page_from_name(cname)
450
- if page = @wiki.page(cname)
450
+ slash = cname.rindex('/')
451
+
452
+ unless slash.nil?
453
+ name = cname[slash+1..-1]
454
+ path = cname[0..slash]
455
+ page = @wiki.paged(name, path)
456
+ else
457
+ page = @wiki.paged(cname, '/')
458
+ end
459
+
460
+ if page
451
461
  return page
452
462
  end
453
463
  if pos = cname.index('#')
@@ -327,7 +327,7 @@ module Gollum
327
327
  # Returns the String canonical name.
328
328
  def self.cname(name, char_white_sub = '-', char_other_sub = '-')
329
329
  name.respond_to?(:gsub) ?
330
- name.gsub(%r{\s},char_white_sub).gsub(%r{[/<>+]}, char_other_sub) :
330
+ name.gsub(%r{\s},char_white_sub).gsub(%r{[<>+]}, char_other_sub) :
331
331
  ''
332
332
  end
333
333
 
@@ -372,9 +372,9 @@ module Gollum
372
372
  # version - The String version ID to find.
373
373
  #
374
374
  # Returns a Gollum::Page or nil if the page could not be found.
375
- def find(name, version, dir = nil)
375
+ def find(name, version, dir = nil, exact = false)
376
376
  map = @wiki.tree_map_for(version.to_s)
377
- if page = find_page_in_tree(map, name, dir)
377
+ if page = find_page_in_tree(map, name, dir, exact)
378
378
  page.version = version.is_a?(Grit::Commit) ?
379
379
  version : @wiki.commit_for(version)
380
380
  page.historical = page.version.to_s == version.to_s
@@ -391,12 +391,14 @@ module Gollum
391
391
  # to be in. The string should
392
392
  #
393
393
  # Returns a Gollum::Page or nil if the page could not be found.
394
- def find_page_in_tree(map, name, checked_dir = nil)
394
+ def find_page_in_tree(map, name, checked_dir = nil, exact = false)
395
395
  return nil if !map || name.to_s.empty?
396
396
  if checked_dir = BlobEntry.normalize_dir(checked_dir)
397
397
  checked_dir.downcase!
398
398
  end
399
399
 
400
+ checked_dir = '' if exact && checked_dir.nil?
401
+
400
402
  map.each do |entry|
401
403
  next if entry.name.to_s.empty?
402
404
  next unless checked_dir.nil? || entry.dir.downcase == checked_dir
@@ -196,9 +196,9 @@ module Gollum
196
196
  # dir - The directory String relative to the repo.
197
197
  #
198
198
  # Returns a Gollum::Page or nil if no matching page was found.
199
- def page(name, version = @ref, dir = nil)
199
+ def page(name, version = @ref, dir = nil, exact = false)
200
200
  version = @ref if version.nil?
201
- @page_class.new(self).find(name, version, dir)
201
+ @page_class.new(self).find(name, version, dir, exact)
202
202
  end
203
203
 
204
204
  # Public: Convenience method instead of calling page(name, nil, dir).
@@ -208,8 +208,8 @@ module Gollum
208
208
  # dir - The directory String relative to the repo.
209
209
  #
210
210
  # Returns a Gollum::Page or nil if no matching page was found.
211
- def paged(name, dir = nil, version = @ref)
212
- page(name, version, dir)
211
+ def paged(name, dir = nil, exact = false, version = @ref)
212
+ page(name, version, dir, exact)
213
213
  end
214
214
 
215
215
  # Public: Get the static file for a given name.
@@ -50,6 +50,14 @@ context "Frontend" do
50
50
  assert_not_equal page_1.version.sha, page_2.version.sha
51
51
  end
52
52
 
53
+ test "edit page with slash" do
54
+ page_1 = @wiki.page('A')
55
+ post "/edit/A", :content => 'abc', :page => 'A', :path => '/////',
56
+ :format => page_1.format, :message => 'def'
57
+ follow_redirect!
58
+ assert last_response.ok?
59
+ end
60
+
53
61
  test "edits page header footer and sidebar" do
54
62
  commits = @wiki.repo.commits('master').size
55
63
  page_1 = @wiki.page('A')
@@ -176,6 +184,7 @@ context "Frontend" do
176
184
  name = "A"
177
185
  post "/create", :content => 'abc', :page => name,
178
186
  :format => 'markdown', :message => 'def'
187
+ follow_redirect!
179
188
  assert last_response.ok?
180
189
 
181
190
  @wiki.clear_cache
@@ -99,7 +99,8 @@ context "Page" do
99
99
  test "cname" do
100
100
  assert_equal "Foo", Gollum::Page.cname("Foo")
101
101
  assert_equal "Foo-Bar", Gollum::Page.cname("Foo Bar")
102
- assert_equal "Foo---Bar", Gollum::Page.cname("Foo / Bar")
102
+ # / is now a directory delimiter so it must be preserved
103
+ assert_equal "Foo-/-Bar", Gollum::Page.cname("Foo / Bar")
103
104
  assert_equal "José", Gollum::Page.cname("José")
104
105
  assert_equal "モルドール", Gollum::Page.cname("モルドール")
105
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-23 00:00:00.000000000 Z
13
+ date: 2012-08-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grit