From 772ffcc5e8959d3ae85d2766c309ae6fa1458c2e Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Mon, 9 Jul 2012 13:22:45 -0600 Subject: [PATCH 1/3] Ensure ascii only filenames. Fix #423. --- gollum.gemspec | 1 + lib/gollum/frontend/app.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gollum.gemspec b/gollum.gemspec index cd03bc2c..53b2ba75 100644 --- a/gollum.gemspec +++ b/gollum.gemspec @@ -33,6 +33,7 @@ Gem::Specification.new do |s| s.add_dependency('sanitize', "~> 2.0.0") s.add_dependency('nokogiri', "~> 1.4") s.add_dependency('useragent', "~> 0.4.9") + s.add_dependency('stringex', "~> 1.4.0") s.add_development_dependency('RedCloth') s.add_development_dependency('mocha') diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 9ef0a143..6ed58e91 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -3,6 +3,7 @@ require 'sinatra' require 'gollum' require 'mustache/sinatra' require 'useragent' +require 'stringex' require 'gollum/frontend/views/layout' require 'gollum/frontend/views/editable' @@ -142,7 +143,7 @@ module Precious end post '/create' do - name = params[:page] + name = params[:page].to_ascii path = sanitize_empty_params(params[:path]) format = params[:format].intern From 3d2c8e7cc57bbb0790c6baf8184587dc2dcf70ac Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Mon, 9 Jul 2012 13:33:14 -0600 Subject: [PATCH 2/3] ASCII only filenames. Fix test_unicode. --- lib/gollum/frontend/app.rb | 2 +- test/test_unicode.rb | 33 +++++++++++---------------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 6ed58e91..c48c0fdf 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -143,7 +143,7 @@ module Precious end post '/create' do - name = params[:page].to_ascii + name = params[:page].to_url path = sanitize_empty_params(params[:path]) format = params[:format].intern diff --git a/test/test_unicode.rb b/test/test_unicode.rb index 35c6a3bb..38a31f8d 100644 --- a/test/test_unicode.rb +++ b/test/test_unicode.rb @@ -16,16 +16,16 @@ context "Unicode Support" do end test "create and read non-latin page" do - @wiki.write_page("한글 test", :markdown, "# 한글") + @wiki.write_page("test", :markdown, "# 한글") - page = @wiki.page("한글 test") + page = @wiki.page("test") assert_equal Gollum::Page, page.class assert_equal "# 한글", utf8(page.raw_data) end test "unicode with existing format rules" do - @wiki.write_page("한글 test", :markdown, "# 한글") - assert_equal @wiki.page("한글 test").path, @wiki.page("한글-test").path + @wiki.write_page("test", :markdown, "# 한글") + assert_equal @wiki.page("test").path, @wiki.page("test").path end end @@ -43,24 +43,13 @@ context "Frontend Unicode support" do FileUtils.rm_rf(@path) end - test "creates korean page" do - post "/create", :content => 'english text', :page => "한글", - :format => 'markdown', :message => 'def' - follow_redirect! - assert last_response.ok? - - page = @wiki.page('한글') - assert_equal 'english text', page.raw_data - assert_equal 'def', page.version.message - end - test "creates korean page which contains korean content" do - post "/create", :content => '한글 text', :page => "한글", + post "/create", :content => '한글 text', :page => "k", :format => 'markdown', :message => 'def' follow_redirect! assert last_response.ok? - page = @wiki.page('한글') + page = @wiki.page('k') assert_equal '한글 text', utf8(page.raw_data) assert_equal 'def', page.version.message end @@ -86,23 +75,23 @@ context "Frontend Unicode support" do end test "heavy use 2" do - post "/create", :content => '한글 text', :page => "한글", + post "/create", :content => '한글 text', :page => "k", :format => 'markdown', :message => 'def' follow_redirect! assert last_response.ok? - @wiki.update_page(@wiki.page('한글'), nil, nil, '다른 text', {}) + @wiki.update_page(@wiki.page('k'), nil, nil, '다른 text', {}) @wiki = Gollum::Wiki.new(@path) - page = @wiki.page('한글') + page = @wiki.page('k') assert_equal '다른 text', utf8(page.raw_data) - post '/edit/' + CGI.escape('한글'), :page => '한글', :content => '바뀐 text', + post '/edit/' + CGI.escape('한글'), :page => 'k', :content => '바뀐 text', :format => 'markdown', :message => 'ghi' follow_redirect! assert last_response.ok? @wiki = Gollum::Wiki.new(@path) - page = @wiki.page('한글') + page = @wiki.page('k') assert_equal '바뀐 text', utf8(page.raw_data) assert_equal 'ghi', page.version.message end From 5714cef3de88422b0b66a5622b0f35b151b2690c Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 10 Jul 2012 10:47:15 -0600 Subject: [PATCH 3/3] Page names are no longer case sensitive. --- test/test_app.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_app.rb b/test/test_app.rb index cf60576d..e4d2d875 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -113,7 +113,7 @@ context "Frontend" do test "creates pages with escaped characters in title" do post "/create", :content => 'abc', :page => 'Title with spaces', :format => 'markdown', :message => 'foo' - assert_equal 'http://example.org/Title-with-spaces', last_response.headers['Location'] + assert_equal 'http://example.org/title-with-spaces', last_response.headers['Location'] get "/Title-with-spaces" assert_match /abc/, last_response.body end @@ -275,13 +275,13 @@ context "Frontend with lotr" do test "create pages within sub-directories" do post "/create", :content => 'big smelly creatures', :page => 'Orc', :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', last_response.headers['Location'] get "/Mordor/Orc" assert_match /big smelly creatures/, last_response.body post "/create", :content => 'really big smelly creatures', :page => 'Uruk Hai', :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-hai', last_response.headers['Location'] get "/Mordor/Uruk-Hai" assert_match /really big smelly creatures/, last_response.body end @@ -289,11 +289,11 @@ context "Frontend with lotr" do test "edit pages within sub-directories" do post "/create", :content => 'big smelly creatures', :page => 'Orc', :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', last_response.headers['Location'] post "/edit/Mordor/Orc", :content => 'not so big smelly creatures', :page => 'Orc', :path => 'Mordor', :message => 'minor edit' - assert_equal 'http://example.org/Mordor/Orc', last_response.headers['Location'] + assert_equal 'http://example.org/Mordor/orc', last_response.headers['Location'] get "/Mordor/Orc" assert_match /not so big smelly creatures/, last_response.body