Make reordering work in Ruby 1.8.x

I was fooled: Ruby 1.9 has ordered
hashes; 1.8 doesn't. So what I did
in Revision 689 works in Ruby 1.9,
but fails in 1.8.

Now we parse the POST params ourselves.
This commit is contained in:
Jacques Distler 2010-10-10 13:24:05 -05:00
parent b7806c12ce
commit 8a989b1a7b
2 changed files with 6 additions and 7 deletions

View file

@ -189,7 +189,9 @@ EOL
return unless is_post return unless is_post
if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup)
@tex_content = '' @tex_content = ''
params.each do |name, p| # Ruby 1.9.x has ordered hashes; 1.8.x doesn't. So let's just parse the query ourselves.
ordered_params = ActiveSupport::OrderedHash[*request.raw_post.split('&').collect {|k_v| k_v.split('=').each {|x| CGI::unescape(x)}}.flatten]
ordered_params.each do |name, p|
if p == 'tex' && @web.has_page?(name) if p == 'tex' && @web.has_page?(name)
@tex_content << "\\section*\{#{name}\}\n\n".as_utf8 @tex_content << "\\section*\{#{name}\}\n\n".as_utf8
@tex_content << Maruku.new(@web.page(name).content).to_latex @tex_content << Maruku.new(@web.page(name).content).to_latex
@ -303,11 +305,7 @@ EOL
def save def save
render(:status => 404, :text => 'Undefined page name', :layout => 'error') and return if @page_name.nil? render(:status => 404, :text => 'Undefined page name', :layout => 'error') and return if @page_name.nil?
unless (request.post? || Rails.env.test?) return unless is_post
headers['Allow'] = 'POST'
render(:status => 405, :text => 'You must use an HTTP POST', :layout => 'error')
return
end
author_name = params['author'].purify author_name = params['author'].purify
author_name = 'AnonymousCoward' if author_name =~ /^\s*$/ author_name = 'AnonymousCoward' if author_name =~ /^\s*$/

View file

@ -1349,7 +1349,8 @@ Page2 contents $\mathbb{01234}$.
@wiki.write_page('wiki1', 'Page2', @wiki.write_page('wiki1', 'Page2',
"Page2 contents $\\mathbb{01234}$.\n", "Page2 contents $\\mathbb{01234}$.\n",
Time.now, Author.new('AnotherAuthor', '127.0.0.2'), x_test_renderer) Time.now, Author.new('AnotherAuthor', '127.0.0.2'), x_test_renderer)
r = process('tex_list', 'web' => 'wiki1', 'Page2' => 'tex', 'BogusPage'=> 'tex', 'HomePage' => 'tex') @request.env['RAW_POST_DATA'] = "_form_key=353106ff8c8466727ee5338baaa0640c87c9b0d6&Page2=tex&BogusPage=tex&HomePage=tex&commit=Export"
r = process('tex_list', 'web' => 'wiki1', 'Page2' => 'tex', 'BogusPage'=> 'tex', 'HomePage' => 'tex')
assert_response(:success) assert_response(:success)
assert_equal @tex_header1 + "\\usepackage{mathbbol}\n" + @tex_header2 + %q!\section*{Page2} assert_equal @tex_header1 + "\\usepackage{mathbbol}\n" + @tex_header2 + %q!\section*{Page2}