Merge branch 'master' of git.sv.gnu.org:/srv/git/oddmuse

This commit is contained in:
Alex Schroeder
2013-10-25 08:50:51 +02:00
5 changed files with 66 additions and 18 deletions

View File

@@ -24,7 +24,20 @@ sub FixEncoding {
OpenPage($id);
my $text = $Page{text};
utf8::decode($text);
Save($id, $text, 'fix encoding', 1) if $text ne $Page{text};
Save($id, $text, T('Fix character encoding'), 1) if $text ne $Page{text};
ReleaseLock();
ReBrowsePage($id);
}
$Action{'fix-escaping'} = \&FixEscaping;
sub FixEscaping {
my $id = shift;
ValidIdOrDie($id);
RequestLockOrError();
OpenPage($id);
my $text = UnquoteHtml($Page{text});
Save($id, $text, T('Fix HTML escapes'), 1) if $text ne $Page{text};
ReleaseLock();
ReBrowsePage($id);
}
@@ -35,6 +48,10 @@ sub FixEncodingMenu {
my ($id, $menuref, $restref) = @_;
if ($id) {
push(@$menuref,
ScriptLink('action=fix-encoding;id=' . UrlEncode($id), T('Fix page encoding')));
ScriptLink('action=fix-encoding;id=' . UrlEncode($id),
T('Fix character encoding')));
push(@$menuref,
ScriptLink('action=fix-escaping;id=' . UrlEncode($id),
T('Fix HTML escapes')));
}
}

View File

@@ -231,7 +231,8 @@ sub NewReCaptchaDoPost {
print $q->start_div({-class=>'error'});
print $q->p(T('You did not answer correctly.'));
print GetFormStart(), ReCaptchaGetQuestion(1),
(map { $q->input({-type=>'hidden', -name=>$_, -value=>GetParam($_)}) }
(map { $q->input({-type=>'hidden', -name=>$_,
-value=>UnquoteHtml(GetParam($_))}) }
qw(title text oldtime summary recent_edit aftertext)), $q->end_form;
print $q->end_div();
PrintFooter();

View File

@@ -672,7 +672,7 @@ ordinary changes
normale Änderungen
Matching page names:
Übereinstimmende Seitennamen:
Fix page encoding
Fix character encoding
Zeichenkodierung korrigieren
no summary available
keine Zusammenfassug vorhanden

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2012 Alex Schroeder <alex@gnu.org>
# Copyright (C) 20122013 Alex Schroeder <alex@gnu.org>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
@@ -14,7 +14,7 @@
require 't/test.pl';
package OddMuse;
use Test::More tests => 12;
use Test::More tests => 20;
use utf8; # tests contain UTF-8 characters and it matters
clear_pages();
@@ -26,14 +26,19 @@ test_page_negative(get_page('action=admin'), 'action=fix-encoding');
# make sure no menu shows up if the page does not exists
test_page(get_page('action=admin id=foo'), 'action=fix-encoding;id=foo');
test_page(get_page('action=admin id=foo'),
'action=fix-encoding;id=foo',
'action=fix-escaping;id=foo');
# make sure nothing is saved if the page does not exist
test_page(get_page('action=fix-encoding id=Example'),
'Location: http://localhost/wiki.pl/Example');
test_page_negative(get_page('action=rc showedit=1'), 'fix encoding');
test_page(get_page('action=fix-escaping id=Example'),
'Location: http://localhost/wiki.pl/Example');
test_page_negative(get_page('action=rc all=1 showedit=1'), 'fix');
# make sure nothing is saved if there is no change
@@ -43,14 +48,19 @@ test_page(update_page('Example', 'Pilgerstätte für die Göttin'),
test_page(get_page('action=fix-encoding id=Example'),
'Location: http://localhost/wiki.pl/Example');
test_page_negative(get_page('action=rc showedit=1'), 'fix encoding');
test_page(get_page('action=fix-escaping id=Example'),
'Location: http://localhost/wiki.pl/Example');
test_page_negative(get_page('action=rc all=1 showedit=1'),
'Fix Character encoding');
# the menu shows up if the page exists
test_page(get_page('action=admin id=Example'),
'action=fix-encoding;id=Example');
'action=fix-encoding;id=Example',
'action=fix-escaping;id=Example');
# here is an actual page you need to fix
# here is an actual page with a character encoding error you need to fix
test_page(update_page('Example', 'Pilgerstätte für die Göttin',
'borked encoding'),
@@ -62,4 +72,20 @@ test_page(get_page('action=fix-encoding id=Example'),
test_page(get_page('Example'),
'Pilgerstätte für die Göttin');
test_page(get_page('action=rc showedit=1'), 'fix encoding');
test_page(get_page('action=rc showedit=1'),
'Fix character encoding');
# here is an actual page with an HTML escaping error you need to fix
test_page(update_page('Example', '&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;',
'borked escaping'),
'&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;');
test_page(get_page('action=fix-escaping id=Example'),
'Location: http://localhost/wiki.pl/Example');
test_page(get_page('Example'),
'&lt;b&gt;bold&lt;/b&gt;');
test_page(get_page('action=rc showedit=1'),
'Fix HTML escapes');

View File

@@ -21,14 +21,18 @@ use utf8; # test data is UTF-8 and it matters
clear_pages();
$ENV{'REMOTE_ADDR'}='127.0.0.1';
add_module('recaptcha.pl');
# The recaptcha module used to corrupt UTF-8 encoding and HTML
# escaping.
# non-existing page and no permission
test_page(get_page('title=SandBox text=K%C3%BChlschrank'),
test_page(get_page('title=SandBox text="<b>K%C3%BChlschrank</b>"'),
'Status: 403',
'Kühlschrank');
'&lt;b&gt;Kühlschrank&lt;/b&gt;');
# update it as an admin
test_page(update_page('SandBox', 'Kühlschrank', undef, undef, 1),
'Kühlschrank');
test_page(update_page('SandBox', '<b>Kühlschrank</b>', undef, undef, 1),
'&lt;b&gt;Kühlschrank&lt;/b&gt;');
# existing page and no permission
test_page(get_page('title=SandBox text=K%C3%BChlschrank-test'),
test_page(get_page('title=SandBox text="<b>K%C3%BChlschrank-test</b>"'),
'Status: 403',
'Kühlschrank-test');
'&lt;b&gt;Kühlschrank-test&lt;/b&gt;');