• 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.

Item5880: TablePlugin may delete query parameters after reordering some table

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension TablePlugin Urgent Closed   patch 4.2.2, 5.0.0

Edit Form Data

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

Detail

TWiki:Plugins.TablePlugin can sort tables by column values. It turns header cell into links with parameters containing info about desired sort order. It should preserve other existing parameters, and it does, since parameters names doesn't end in up and doesn't have numeric values. The reason is that TablePlugin, when generate new links, delete current sort parameters and insert new ones. It performs this task with a greed regex instead of using delete method (available at bot CGI and TWiki::Request).

Example:

Fill the form bellow and submit.

Sortcolumn
Foo
Cup
Bar

Now, all submitted values are displayed. Click on some header cell on the table bellow.

H1 H2 H3
abc 234 xyz
def 056 qwe
987 foo bar

If you filled Cup with some numeric value (or something that starts with a number), them the first three fields are empty after sort. Bar value is preserved.

This problem is very unlikely to occur, but it's easy to fix.

-- TWiki:Main/GilmarSantosJr - 04 Aug 2008

I suggest the following fix:

=== lib/TWiki/Plugins/TablePlugin/Core.pm
==================================================================
--- lib/TWiki/Plugins/TablePlugin/Core.pm       (revision 15801)
+++ lib/TWiki/Plugins/TablePlugin/Core.pm       (local)
@@ -1687,13 +1687,21 @@
         my $cgi = TWiki::Func::getCgiQuery();
         return unless $cgi;
 
-        # Extract and attach existing parameters
-        my $plist = $cgi->query_string();
-        $plist =~ s/\;/\&/go;
-        $plist =~ s/\&?sortcol.*up=[0-9]+\&?//go;
-        $plist .= '&' if $plist;
-        $url = $cgi->url . $cgi->path_info() . '?' . $plist;
-        $url =~ s/\&/\&/go;
+        # Copy existing values
+        my (@origSort, @origTable, @origUp);
+        @origSort  = $cgi->param('sortcol');
+        @origTable = $cgi->param('table');
+        @origUp    = $cgi->param('up');
+        $cgi->delete('sortcol', 'table', 'up');
+        $url = $cgi->url(-full => 1, -path => 1) . '?';
+        my $queryString = $cgi->query_string();
+        $url .= $queryString . ';' if $queryString;
+
+        # Restore parameters, so we don't interfere on the remaining execution
+        $cgi->param( -name => 'sortcol', -value => \@origSort );
+        $cgi->param( -name => 'table',   -value => \@origTable );
+        $cgi->param( -name => 'up',      -value => \@origUp );
+
         $sortColFromUrl =
           $cgi->param('sortcol');    # zero based: 0 is first column
         $requestedTable = $cgi->param('table');

Waiting for feedback from someone else to commit.

-- TWiki:Main.GilmarSantosJr - 04 Aug 2008

Will these proposed changes work on 4.2 and 4.1 of TWiki?

Marked urgent. Added (trunk) to title.

-- TWiki:Main.KennethLavrsen - 04 Aug 2008

The delete method is available on TWiki::Request with the same semantics of CGI::delete, so it should work. I'll test this change with TWikiRelease04x02 and report results.

-- TWiki:Main.GilmarSantosJr - 04 Aug 2008

I've just tested and the problem is present in TWikiRelease04x02. The fix applies as well. So, should I merge to TWikiRelease04x02 branch? (removed "trunk" from title, since the problem also existis in 4.2)

-- TWiki:Main.GilmarSantosJr - 05 Aug 2008

Yes please merge fixes also to TWikiRelease04x02 branch so we can have them in 4.2.2.

-- TWiki:Main.KennethLavrsen - 05 Aug 2008

Done wink

-- TWiki:Main.GilmarSantosJr - 05 Aug 2008

Revision 17326 breaks repeated sorting of columns because url parameters are copied. The url gets multiple instances of up=0. Reopening.

-- TWiki:Main.ArthurClemens - 30 Sep 2008

That revision indirectly caused the problem. The root was at TWiki::Response::delete, that didn't work if parameter value was false, like this case. I fixed it at Item6035. smile

I also updated unit tests, so they can work with 4.2: TWikiFnTestCase makes the request object (either TWiki::Request or CGI) available at $this->{request}. Take a look at Item5911. wink

-- TWiki:Main.GilmarSantosJr - 01 Oct 2008

You mean that a new bug item is needed? Because the bug is still there. I will do it for you: Item6038.

-- TWiki:Main.ArthurClemens - 01 Oct 2008

Works now indeed.

-- TWiki:Main.ArthurClemens - 01 Oct 2008

ItemTemplate
Summary TablePlugin may delete query parameters after reordering some table
ReportedBy TWiki:Main.GilmarSantosJr
Codebase 4.2.0, 4.2.1, ~twiki4
SVN Range TWiki-5.0.0, Sun, 03 Aug 2008, build 17280
AppliesTo Extension
Component TablePlugin
Priority Urgent
CurrentState Closed
WaitingFor

Checkins TWikirev:17326 TWikirev:17328
TargetRelease patch
ReleasedIn 4.2.2, 5.0.0
Edit | Attach | Watch | Print version | History: r15 < r14 < r13 < r12 < r11 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r15 - 2008-10-01 - ArthurClemens
 
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