Remove ws subs (#1220)
* remove unwanted whitespace substitution * end repression of file extensions * see also https://github.com/gollum/gollum-lib/pull/249
This commit is contained in:
+17
-21
@@ -18,20 +18,16 @@ require File.expand_path '../helpers', __FILE__
|
|||||||
Gollum::set_git_timeout(120)
|
Gollum::set_git_timeout(120)
|
||||||
Gollum::set_git_max_filesize(190 * 10**6)
|
Gollum::set_git_max_filesize(190 * 10**6)
|
||||||
|
|
||||||
# Fix to_url
|
# Use stringex #to_url only to leverage its #to_ascii method when using grit
|
||||||
class String
|
class String
|
||||||
alias :upstream_to_url :to_url
|
|
||||||
|
|
||||||
if defined?(Gollum::GIT_ADAPTER) && Gollum::GIT_ADAPTER != 'grit'
|
if defined?(Gollum::GIT_ADAPTER) && Gollum::GIT_ADAPTER != 'grit'
|
||||||
def to_ascii
|
def to_ascii
|
||||||
self # Do not transliterate utf-8 url's unless using Grit
|
self # Do not transliterate utf-8 url's unless using Grit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# _Header => header which causes errors
|
|
||||||
def to_url
|
def to_url
|
||||||
return nil if self.nil?
|
to_ascii
|
||||||
upstream_to_url :exclude => ['_Header', '_Footer', '_Sidebar'], :force_downcase => false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -120,12 +116,12 @@ module Precious
|
|||||||
def wiki_page(name, path = nil, version = nil, exact = true)
|
def wiki_page(name, path = nil, version = nil, exact = true)
|
||||||
wiki = wiki_new
|
wiki = wiki_new
|
||||||
path = name if path.nil?
|
path = name if path.nil?
|
||||||
name = extract_name(name) || wiki.index_page
|
name, ext = extract_name(name) || wiki.index_page
|
||||||
path = extract_path(path)
|
path = extract_path(path)
|
||||||
path = '/' if exact && path.nil?
|
path = '/' if exact && path.nil?
|
||||||
|
|
||||||
OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, exact, version),
|
OpenStruct.new(:wiki => wiki, :page => wiki.paged(join_page_name(name, ext), path, exact, version),
|
||||||
:name => name, :path => path)
|
:name => name, :path => path, :ext => ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wiki_new
|
def wiki_new
|
||||||
@@ -157,7 +153,7 @@ module Precious
|
|||||||
get '/edit/*' do
|
get '/edit/*' do
|
||||||
forbid unless @allow_editing
|
forbid unless @allow_editing
|
||||||
wikip = wiki_page(params[:splat].first)
|
wikip = wiki_page(params[:splat].first)
|
||||||
@name = wikip.name
|
@name = join_page_name(wikip.name, wikip.ext)
|
||||||
@path = wikip.path
|
@path = wikip.path
|
||||||
@upload_dest = find_upload_dest(@path)
|
@upload_dest = find_upload_dest(@path)
|
||||||
|
|
||||||
@@ -247,7 +243,7 @@ module Precious
|
|||||||
wikip = wiki_page(params[:splat].first)
|
wikip = wiki_page(params[:splat].first)
|
||||||
halt 500 if wikip.nil?
|
halt 500 if wikip.nil?
|
||||||
wiki = wikip.wiki
|
wiki = wikip.wiki
|
||||||
page = wiki.paged(wikip.name, wikip.path, exact = true)
|
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||||
rename = params[:rename]
|
rename = params[:rename]
|
||||||
halt 500 if page.nil?
|
halt 500 if page.nil?
|
||||||
halt 500 if rename.nil? or rename.empty?
|
halt 500 if rename.nil? or rename.empty?
|
||||||
@@ -274,7 +270,7 @@ module Precious
|
|||||||
committer.commit
|
committer.commit
|
||||||
|
|
||||||
wikip = wiki_page(rename)
|
wikip = wiki_page(rename)
|
||||||
page = wiki.paged(wikip.name, wikip.path, exact = true)
|
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||||
return if page.nil?
|
return if page.nil?
|
||||||
redirect to("/#{page.escaped_url_path}")
|
redirect to("/#{page.escaped_url_path}")
|
||||||
end
|
end
|
||||||
@@ -300,7 +296,7 @@ module Precious
|
|||||||
get '/delete/*' do
|
get '/delete/*' do
|
||||||
forbid unless @allow_editing
|
forbid unless @allow_editing
|
||||||
wikip = wiki_page(params[:splat].first)
|
wikip = wiki_page(params[:splat].first)
|
||||||
name = wikip.name
|
name = join_page_name(wikip.name, wikip.ext)
|
||||||
wiki = wikip.wiki
|
wiki = wikip.wiki
|
||||||
page = wikip.page
|
page = wikip.page
|
||||||
unless page.nil?
|
unless page.nil?
|
||||||
@@ -319,7 +315,7 @@ module Precious
|
|||||||
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed."
|
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed."
|
||||||
end
|
end
|
||||||
wikip = wiki_page(params[:splat].first.gsub('+', '-'))
|
wikip = wiki_page(params[:splat].first.gsub('+', '-'))
|
||||||
@name = wikip.name.to_url
|
@name, ext = wikip.name.to_url
|
||||||
@path = wikip.path
|
@path = wikip.path
|
||||||
@allow_uploads = wikip.wiki.allow_uploads
|
@allow_uploads = wikip.wiki.allow_uploads
|
||||||
@upload_dest = find_upload_dest(@path)
|
@upload_dest = find_upload_dest(@path)
|
||||||
@@ -354,7 +350,7 @@ module Precious
|
|||||||
wiki.write_page(name, format, params[:content], commit_message, path)
|
wiki.write_page(name, format, params[:content], commit_message, path)
|
||||||
|
|
||||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||||
redirect to("/#{clean_url(::File.join(page_dir, path, encodeURIComponent(name)))}")
|
redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}")
|
||||||
rescue Gollum::DuplicatePageError => e
|
rescue Gollum::DuplicatePageError => e
|
||||||
@message = "Duplicate page: #{e.message}"
|
@message = "Duplicate page: #{e.message}"
|
||||||
mustache :error
|
mustache :error
|
||||||
@@ -364,7 +360,7 @@ module Precious
|
|||||||
post '/revert/*/:sha1/:sha2' do
|
post '/revert/*/:sha1/:sha2' do
|
||||||
wikip = wiki_page(params[:splat].first)
|
wikip = wiki_page(params[:splat].first)
|
||||||
@path = wikip.path
|
@path = wikip.path
|
||||||
@name = wikip.name
|
@name = join_page_name(wikip.name, wikip.ext)
|
||||||
wiki = wikip.wiki
|
wiki = wikip.wiki
|
||||||
@page = wiki.paged(@name, @path)
|
@page = wiki.paged(@name, @path)
|
||||||
sha1 = params[:sha1]
|
sha1 = params[:sha1]
|
||||||
@@ -446,7 +442,7 @@ module Precious
|
|||||||
}x do |path, start_version, end_version|
|
}x do |path, start_version, end_version|
|
||||||
wikip = wiki_page(path)
|
wikip = wiki_page(path)
|
||||||
@path = wikip.path
|
@path = wikip.path
|
||||||
@name = wikip.name
|
@name = join_page_name(wikip.name, wikip.ext)
|
||||||
@versions = [start_version, end_version]
|
@versions = [start_version, end_version]
|
||||||
wiki = wikip.wiki
|
wiki = wikip.wiki
|
||||||
@page = wikip.page
|
@page = wikip.page
|
||||||
@@ -459,7 +455,7 @@ module Precious
|
|||||||
file_path = params[:captures][0]
|
file_path = params[:captures][0]
|
||||||
version = params[:captures][1]
|
version = params[:captures][1]
|
||||||
wikip = wiki_page(file_path, file_path, version)
|
wikip = wiki_page(file_path, file_path, version)
|
||||||
name = wikip.name
|
name = join_page_name(wikip.name, wikip.ext)
|
||||||
path = wikip.path
|
path = wikip.path
|
||||||
if page = wikip.page
|
if page = wikip.page
|
||||||
@page = page
|
@page = page
|
||||||
@@ -520,9 +516,9 @@ module Precious
|
|||||||
def show_page_or_file(fullpath)
|
def show_page_or_file(fullpath)
|
||||||
wiki = wiki_new
|
wiki = wiki_new
|
||||||
|
|
||||||
name = extract_name(fullpath) || wiki.index_page
|
name, ext = extract_name(fullpath) || wiki.index_page
|
||||||
path = extract_path(fullpath) || '/'
|
path = extract_path(fullpath) || '/'
|
||||||
if page = wiki.paged(name, path, exact = true)
|
if page = wiki.paged(join_page_name(name, ext), path, exact = true)
|
||||||
@page = page
|
@page = page
|
||||||
@name = name
|
@name = name
|
||||||
@content = page.formatted_data
|
@content = page.formatted_data
|
||||||
@@ -541,7 +537,7 @@ module Precious
|
|||||||
show_file(file)
|
show_file(file)
|
||||||
else
|
else
|
||||||
not_found unless @allow_editing
|
not_found unless @allow_editing
|
||||||
page_path = [path, name].compact.join('/')
|
page_path = [path, join_page_name(name, ext)].compact.join('/')
|
||||||
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ module Precious
|
|||||||
|
|
||||||
EMOJI_PATHNAME = Pathname.new(Gemojione.images_path).freeze
|
EMOJI_PATHNAME = Pathname.new(Gemojione.images_path).freeze
|
||||||
|
|
||||||
|
def join_page_name(name, ext)
|
||||||
|
"#{name}#{ext}"
|
||||||
|
end
|
||||||
|
|
||||||
# Extract the path string that Gollum::Wiki expects
|
# Extract the path string that Gollum::Wiki expects
|
||||||
def extract_path(file_path)
|
def extract_path(file_path)
|
||||||
return nil if file_path.nil?
|
return nil if file_path.nil?
|
||||||
@@ -23,7 +27,8 @@ module Precious
|
|||||||
|
|
||||||
# File.basename is too eager to please and will return the last
|
# File.basename is too eager to please and will return the last
|
||||||
# component of the path even if it ends with a directory separator.
|
# component of the path even if it ends with a directory separator.
|
||||||
::File.basename(file_path)
|
ext = ::File.extname(file_path)
|
||||||
|
return ::File.basename(file_path, ext), ext
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_empty_params(param)
|
def sanitize_empty_params(param)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
var baseUrl = '{{base_url}}';
|
var baseUrl = '{{base_url}}';
|
||||||
var uploadDest = '{{upload_dest}}';
|
var uploadDest = '{{upload_dest}}';
|
||||||
{{#page}}
|
{{#page}}
|
||||||
var pageFullPath = '{{url_path_display}}';
|
var pageFullPath = '{{url_path}}';
|
||||||
{{/page}}
|
{{/page}}
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="{{base_url}}/javascript/jquery-1.7.2.min.js"></script>
|
<script type="text/javascript" src="{{base_url}}/javascript/jquery-1.7.2.min.js"></script>
|
||||||
|
|||||||
+9
-32
@@ -15,29 +15,6 @@ context "Frontend" do
|
|||||||
FileUtils.rm_rf(@path)
|
FileUtils.rm_rf(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "urls transform unicode" do
|
|
||||||
header = '_Header'
|
|
||||||
footer = '_Footer'
|
|
||||||
sidebar = '_Sidebar'
|
|
||||||
|
|
||||||
# header, footer, and sidebar must be preserved
|
|
||||||
# or gollum will not recognize them
|
|
||||||
assert_equal header, header.to_url
|
|
||||||
assert_equal footer, footer.to_url
|
|
||||||
assert_equal sidebar, sidebar.to_url
|
|
||||||
|
|
||||||
# spaces are converted to dashes in URLs
|
|
||||||
# and in file names saved to disk
|
|
||||||
# urls are not case sensitive
|
|
||||||
assert_equal 'Title-Space', 'Title Space'.to_url
|
|
||||||
|
|
||||||
# ascii only file names prevent UTF8 issues
|
|
||||||
# when using git repos across operating systems
|
|
||||||
# as this test demonstrates, translation is not
|
|
||||||
# great
|
|
||||||
assert_equal 'm-plus-F', 'μ†ℱ'.to_url
|
|
||||||
end
|
|
||||||
|
|
||||||
test "utf-8 kcode" do
|
test "utf-8 kcode" do
|
||||||
assert_equal 'μ†ℱ'.scan(/./), ["μ", "†", "ℱ"]
|
assert_equal 'μ†ℱ'.scan(/./), ["μ", "†", "ℱ"]
|
||||||
end
|
end
|
||||||
@@ -255,8 +232,8 @@ context "Frontend" do
|
|||||||
test "creates pages with escaped characters in title" do
|
test "creates pages with escaped characters in title" do
|
||||||
post "/create", :content => 'abc', :page => 'Title with spaces',
|
post "/create", :content => 'abc', :page => 'Title with spaces',
|
||||||
:format => 'markdown', :message => 'foo'
|
:format => 'markdown', :message => 'foo'
|
||||||
assert_equal 'http://example.org/Title-with-spaces', last_response.headers['Location']
|
assert_equal 'http://example.org/Title%20with%20spaces.md', last_response.headers['Location']
|
||||||
get "/Title-with-spaces"
|
get "/Title%20with%20spaces"
|
||||||
assert_match /abc/, last_response.body
|
assert_match /abc/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -280,7 +257,7 @@ context "Frontend" do
|
|||||||
post "/create", :content => 'abc', :page => 'Home', :path => '/foo/',
|
post "/create", :content => 'abc', :page => 'Home', :path => '/foo/',
|
||||||
:format => 'markdown', :message => 'foo'
|
:format => 'markdown', :message => 'foo'
|
||||||
|
|
||||||
assert_equal "http://example.org/foo/Home", last_response.headers['Location']
|
assert_equal "http://example.org/foo/Home.md", last_response.headers['Location']
|
||||||
|
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -672,7 +649,7 @@ context "Frontend with lotr" do
|
|||||||
post "/create", :content => '123', :page => page,
|
post "/create", :content => '123', :page => page,
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
# should be wiki/Mordor/path
|
# should be wiki/Mordor/path
|
||||||
assert_equal 'http://example.org/Mordor/' + page, last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/' + page + '.md', last_response.headers['Location']
|
||||||
get '/Mordor/' + page
|
get '/Mordor/' + page
|
||||||
assert_match /123/, last_response.body
|
assert_match /123/, last_response.body
|
||||||
|
|
||||||
@@ -683,7 +660,7 @@ context "Frontend with lotr" do
|
|||||||
test "create pages within sub-directories using page file dir" do
|
test "create pages within sub-directories using page file dir" do
|
||||||
post "/create", :content => 'one two', :page => 'base',
|
post "/create", :content => 'one two', :page => 'base',
|
||||||
:path => 'wiki/Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'wiki/Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
assert_equal 'http://example.org/wiki/Mordor/base', last_response.headers['Location']
|
assert_equal 'http://example.org/wiki/Mordor/base.md', last_response.headers['Location']
|
||||||
get "/wiki/Mordor/base"
|
get "/wiki/Mordor/base"
|
||||||
|
|
||||||
assert_match /one two/, last_response.body
|
assert_match /one two/, last_response.body
|
||||||
@@ -693,14 +670,14 @@ context "Frontend with lotr" do
|
|||||||
test "create pages within sub-directories" do
|
test "create pages within sub-directories" do
|
||||||
post "/create", :content => 'big smelly creatures', :page => 'Orc',
|
post "/create", :content => 'big smelly creatures', :page => 'Orc',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
assert_equal 'http://example.org/Mordor/Orc', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||||
get "/Mordor/Orc"
|
get "/Mordor/Orc"
|
||||||
assert_match /big smelly creatures/, last_response.body
|
assert_match /big smelly creatures/, last_response.body
|
||||||
|
|
||||||
post "/create", :content => 'really big smelly creatures', :page => 'Uruk Hai',
|
post "/create", :content => 'really big smelly creatures', :page => 'Uruk Hai',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, very scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, very scary'
|
||||||
assert_equal 'http://example.org/Mordor/Uruk-Hai', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Uruk%20Hai.md', last_response.headers['Location']
|
||||||
get "/Mordor/Uruk-Hai"
|
get "/Mordor/Uruk%20Hai"
|
||||||
assert_match /really big smelly creatures/, last_response.body
|
assert_match /really big smelly creatures/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -708,7 +685,7 @@ context "Frontend with lotr" do
|
|||||||
post "/create", :content => 'big smelly creatures', :page => 'Orc',
|
post "/create", :content => 'big smelly creatures', :page => 'Orc',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
|
|
||||||
assert_equal 'http://example.org/Mordor/Orc', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||||
|
|
||||||
post "/edit/Mordor/Orc", :content => 'not so big smelly creatures',
|
post "/edit/Mordor/Orc", :content => 'not so big smelly creatures',
|
||||||
:page => 'Orc', :path => 'Mordor', :message => 'minor edit'
|
:page => 'Orc', :path => 'Mordor', :message => 'minor edit'
|
||||||
|
|||||||
@@ -89,10 +89,12 @@ context "Frontend Unicode support" do
|
|||||||
assert_equal 'ghi', page.version.message
|
assert_equal 'ghi', page.version.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'transliteration' do
|
test 'unicode filenames' do
|
||||||
# TODO: Remove to_url once write_page changes are merged.
|
# we transliterate only when adapter is grit
|
||||||
@wiki.write_page('ééééé'.to_url, :markdown, '한글 text', { :name => '', :email => '' })
|
return if defined?(Gollum::GIT_ADAPTER) && Gollum::GIT_ADAPTER != 'grit'
|
||||||
page = @wiki.page('eeeee')
|
|
||||||
|
@wiki.write_page("ééééé".to_url, :markdown, '한글 text', { :name => '', :email => '' })
|
||||||
|
page = @wiki.page("eeeee".to_url)
|
||||||
assert_equal '한글 text', utf8(page.raw_data)
|
assert_equal '한글 text', utf8(page.raw_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user