The
EditRowPlugin is one of those plugins that destructs and reconstructs the complete topic text in order to parse TWikiTables. It does this multiple times per line, but that's another issue.
It parses the topic text by splitting it up into separate lines in perl like this:
foreach my $line (split(/\r?\n/, $text)) {
...
}
That's a code snippet from
TWiki::Plugins::EditRowPlugin::Table::parseTables($text, ...)
. The problem is that
split
splits up
$text = "some string";
and
$text = "some string\n";
into one single line
and thus ignores the trailing newline which is part of the original text. Later on in the code, when the
$text
has been parsed into an array of lines, all seen lines are joined again using a
\n
as a separator
and a trailing \n
no matter if it was in the original text or not . As a result the plugin occasionally alters the text on its way through by adding a spurious newline char.
For example try the following when the
EditRowPlugin is enabled:
TWiki::Func::expandCommonVariables('some string', 'WebHome', 'Main');
results in
"some string\n"
, but should be
"some string"
.
I fixed it this way:
--- lib/TWiki/Plugins/EditRowPlugin.pm (revision 14319)
+++ lib/TWiki/Plugins/EditRowPlugin.pm (working copy)
@@ -73,6 +73,9 @@
while (my ($key, $value) = each %{$vars}) {
$urps->{$key} = $value if $key =~ /^erp_/;
}
+
+ my $endsWithNewline = ($_[0] =~ /\n$/)?1:0;
+
my $content = TWiki::Plugins::EditRowPlugin::Table::parseTables(
@_, $urps);
@@ -130,7 +133,7 @@
}
}
- $_[0] = join("\n", @$content)."\n" if $hasTables;
+ $_[0] = join("\n", @$content).($endsWithNewline?"\n":'') if $hasTables;
}
but maybe there's a better fix.
--
TWiki:Main/MichaelDaum
- 06 Jul 2007