Gentler
Be a little gentler in recovering from Instiki::ValidationErrors, when saving a page. Previously, we threw away all the user's changes upon the redirect. Now we attempt to salvage what he wrote.
This commit is contained in:
parent
a769ef7a84
commit
a503e2b8ac
10 changed files with 23 additions and 13 deletions
|
@ -242,7 +242,14 @@ class WikiController < ApplicationController
|
|||
begin
|
||||
the_content = params['content']
|
||||
filter_spam(the_content)
|
||||
raise Instiki::ValidationError.new('Your content was not valid utf-8.') unless the_content.is_utf8?
|
||||
unless the_content.is_utf8?
|
||||
if @page
|
||||
the_content = @page.content
|
||||
else
|
||||
the_content = ''
|
||||
end
|
||||
raise Instiki::ValidationError.new('Your content was not valid utf-8.')
|
||||
end
|
||||
if @page
|
||||
wiki.revise_page(@web_name, @page_name, the_content, Time.now,
|
||||
Author.new(author_name, remote_ip), PageRenderer.new)
|
||||
|
@ -257,9 +264,9 @@ class WikiController < ApplicationController
|
|||
logger.error e
|
||||
if @page
|
||||
@page.unlock
|
||||
redirect_to :action => 'edit', :web => @web_name, :id => @page_name
|
||||
redirect_to :action => 'edit', :web => @web_name, :id => @page_name, :content => the_content
|
||||
else
|
||||
redirect_to :action => 'new', :web => @web_name, :id => @page_name
|
||||
redirect_to :action => 'new', :web => @web_name, :id => @page_name, :content => the_content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<ul id="authorList">
|
||||
<%- for author in @authors -%>
|
||||
<li>
|
||||
<%= link_to_page author.delete("\x01-\x08\x0B\x0C\x0E-\x1F") %>
|
||||
<%= link_to_page author.purify %>
|
||||
co- or authored:
|
||||
<%= @page_names_by_author[author].collect { |page_name| link_to_page(page_name) }.sort.join ', ' %>
|
||||
</li>
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()',
|
||||
'accept-charset' => 'utf-8' }) do %>
|
||||
<div>
|
||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] || @page.content.delete("\x01-\x08\x0B\x0C\x0E-\x1F")) %></textarea>
|
||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] || (params['content'] || @page.content).purify) %></textarea>
|
||||
<div id="editFormButtons">
|
||||
<input type="submit" value="Submit" accesskey="s"/> as
|
||||
<%= text_field_tag :author, h(@author.delete("\x01-\x08\x0B\x0C\x0E-\x1F")),
|
||||
<%= text_field_tag :author, h(@author.purify),
|
||||
:onfocus => "this.value == 'AnonymousCoward' ? this.value = '' : true;",
|
||||
:onblur => "this.value == '' ? this.value = 'AnonymousCoward' : true" %>
|
||||
|
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<%- @title = "#{@page.plain_name} is locked" -%>
|
||||
|
||||
<p>
|
||||
<%= link_to_page(h(@page.locked_by.delete("\x01-\x08\x0B\x0C\x0E-\x1F"))) %>
|
||||
<%= link_to_page(h(@page.locked_by.purify)) %>
|
||||
<%- if @page.lock_duration(Time.now) == 0 -%>
|
||||
just started editing this page.
|
||||
<%- else -%>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<% form_tag({ :action => 'save', :web => @web.address, :id => @page_name },
|
||||
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName();', 'accept-charset' => 'utf-8' }) do %>
|
||||
|
||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] || '') %></textarea>
|
||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] || (params['content'] || '').purify ) %></textarea>
|
||||
<div id="editFormButtons">
|
||||
<input type="submit" value="Submit" accesskey="s"/> as
|
||||
<%= text_field_tag :author, @author,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<div class="byline">
|
||||
<%= @page.revisions? ? "Revised" : "Created" %> on <%= format_date(@page.revised_at) %>
|
||||
by <%= author_link(@page).delete("\x01-\x08\x0B\x0C\x0E-\x1F") %>
|
||||
by <%= author_link(@page).purify %>
|
||||
<%= "(#{@page.author.ip})" if @page.author.respond_to?(:ip) %>
|
||||
<% if @web.count_pages? %>
|
||||
<% total_chars = @page.content.length %>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
<div class="byline">
|
||||
<%= "Revision from #{format_date(@revision.revised_at)} by" %>
|
||||
<%= link_to_page @revision.author.delete("\x01-\x08\x0B\x0C\x0E-\x1F") %>
|
||||
<%= link_to_page @revision.author.purify %>
|
||||
</div>
|
||||
|
||||
<div class="navigation navfoot">
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
{ :id => 'editForm', :method => 'post', :onsubmit => 'cleanAuthorName();',
|
||||
'accept-charset' => 'utf-8' }) do %>
|
||||
<div>
|
||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(@revision.content.delete("\x01-\x08\x0B\x0C\x0E-\x1F")) %></textarea>
|
||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(@revision.content.purify) %></textarea>
|
||||
<div id="editFormButtons">
|
||||
<input type="submit" value="Update" accesskey="u" /> as
|
||||
<input type="text" name="author" id="authorName" value="<%= h(@author.delete("\x01-\x08\x0B\x0C\x0E-\x1F")) %>"
|
||||
<input type="text" name="author" id="authorName" value="<%= h(@author.purify) %>"
|
||||
onclick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
|
||||
|
|
||||
<span>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
- Last Update: <%= web.last_page.nil? ? format_date(web.created_at) : format_date(web.last_page.revised_at) %><br/>
|
||||
<%- if ! web.last_page.nil? -%>
|
||||
Last Document: <%= link_to_page(web.last_page.name,web) %>
|
||||
<%= web.last_page.revisions? ? "Revised" : "Created" %> by <%= author_link(web.last_page).delete("\x01-\x08\x0B\x0C\x0E-\x1F") %> (<%= web.last_page.current_revision.ip %>)
|
||||
<%= web.last_page.revisions? ? "Revised" : "Created" %> by <%= author_link(web.last_page).purify %> (<%= web.last_page.current_revision.ip %>)
|
||||
<%- end -%>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -37,6 +37,9 @@ class String
|
|||
end
|
||||
#++
|
||||
|
||||
def purify
|
||||
delete("\x01-\x08\x0B\x0C\x0E-\x1F", "\ufffe\uffff")
|
||||
end
|
||||
#:stopdoc:
|
||||
MATHML_ENTITIES = {
|
||||
'Alpha' => 'Α',
|
||||
|
|
Loading…
Reference in a new issue