• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item4336: EditRowPlugin adds spurious newlines

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension EditRowPlugin Urgent Closed   n/a  

Edit Form Data

Summary:
Reported By:
Codebase:
Applies To:
Component:
Priority:
Current State:
Waiting For:
Target Release:
Released In:
 

Detail

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

ItemTemplate
Summary EditRowPlugin adds spurious newlines
ReportedBy TWiki:Main.MichaelDaum
Codebase

SVN Range TWiki-4.1.2, Thu, 28 Jun 2007, build 14298
AppliesTo Extension
Component EditRowPlugin
Priority Urgent
CurrentState Closed
WaitingFor

Checkins TWikirev:14322
TargetRelease n/a
ReleasedIn

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2007-09-02 - KennethLavrsen
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback