From 20c99df4408514effe0e635855ecb1b006a5013a Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Mon, 19 Oct 2009 18:19:31 -0500 Subject: [PATCH] Work around Rails flash bug When redirected to another page, flash messages will not display if the query string is longer than 10192 bytes. In Instiki, certain rescue operations involve redirection, with the updated content of the page passed as a query parameter. Fall back to using the stored content (ie, don't pass a query parameter) if the content is too long. --- app/controllers/wiki_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 0bea8858..9ca68772 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -273,7 +273,8 @@ class WikiController < ApplicationController if @page new_name = params['new_name'] ? params['new_name'].purify : @page_name raise Instiki::ValidationError.new('Your new title cannot contain a "."') if new_name.include? '.' - raise Instiki::ValidationError.new('A page named "' + new_name.escapeHTML + '" already exists.') if @page_name != new_name && @web.has_page?(new_name) + raise Instiki::ValidationError.new('A page named "' + new_name.escapeHTML + '" already exists.') if + @page_name != new_name && @web.has_page?(new_name) wiki.revise_page(@web_name, @page_name, new_name, the_content, Time.now, Author.new(author_name, remote_ip), PageRenderer.new) @page.unlock @@ -286,11 +287,15 @@ class WikiController < ApplicationController rescue Instiki::ValidationError => e flash[:error] = e.to_s logger.error e + param_hash = {:web => @web_name, :id => @page_name} + # Work around Rails bug: flash will not display if query string is longer than 10192 bytes + param_hash.update( :content => the_content ) if the_content && + CGI::escape(the_content).length < 10183 && the_content != @page.current_revision.content if @page @page.unlock - redirect_to :action => 'edit', :web => @web_name, :id => @page_name, :content => the_content + redirect_to param_hash.update( :action => 'edit' ) else - redirect_to :action => 'new', :web => @web_name, :id => @page_name, :content => the_content + redirect_to param_hash.update( :action => 'new' ) end end end