When no sort is specified in a table's header a notice is thrown:

Notice: Undefined offset: 0 in TableSort->order() (line 131 of /home/ben/projects/d7/head/includes/tablesort.inc).

because the default ordering off the first column assumes a numeric key,

You can see this in core if you remove the sort on 'member_for' from user_admin_account()

Attached patch uses array_keys() to get the first header key.

Comments

Status: Needs review » Needs work

The last submitted patch, , failed testing.

Status: Needs work » Needs review

Re-test of from comment #0 was requested by @user.

Status: Needs review » Needs work

The last submitted patch, , failed testing.

coltrane’s picture

Status: Needs work » Needs review

Setting back to CNR

Re-test of tablesort-error-no-default-sort.patch from comment @comment was requested by coltrane.

effulgentsia’s picture

effulgentsia’s picture

Component: theme system » database system
Status: Needs review » Needs work
Issue tags: +Needs tests

I'm not so sure about the use of array_pop(), but I agree that if there's a situation where a '0' index can't be assumed, then we need to fix it to be more robust. Can you please add a test that demonstrates the bug by failing with HEAD and that passes with the patch? Thanks. Also, I'm moving this to the "database system" since I think people watching those issues should see this too.

coltrane’s picture

A test is a good idea. Instead of array_pop() what do you propose?

effulgentsia’s picture

Instead of array_pop() what do you propose?

How about emulating the code above it that uses a local variable $header by doing:

$headers = array_values($this->header);
$header = $headers[0];
coltrane’s picture

StatusFileSize
new1.06 KB

Right on, that looks good. Here's an updated patch. I'll work on a test soon.

coltrane’s picture

Status: Needs work » Needs review
StatusFileSize
new32.12 KB
new3.06 KB

The attached file is for testing that the TableSort error does not happen when no sort is set. It should fail without the patch in #11 applied but it does not, even though there are notices thrown in the testing results that show the error. I'm using the assertion assertNoText but I'm obviously doing something wrong. The attached PNG shows the testing output.

coltrane’s picture

Issue tags: -Needs tests

(Removing tag)

effulgentsia’s picture

StatusFileSize
new4.13 KB

Combines #11 with the test in #12. I removed the assertion from the test, because the PHP notices themselves cause a simpletest exception, which is all we need. I confirmed that the test does fail in HEAD and pass with the patch, and the code in the patch looks good to me.

@coltrane: once bot goes green, please review the patch to make sure I didn't mess anything up in the re-roll, and if it looks good to you, please RTBC.

Status: Needs review » Needs work

The last submitted patch, 664042-tablesort-error-14.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review

#14: 664042-tablesort-error-14.patch queued for re-testing.

coltrane’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

realityloop’s picture

#14: 664042-tablesort-error-14.patch queued for re-testing.

berdir’s picture

#14: 664042-tablesort-error-14.patch queued for re-testing.

marcingy’s picture

#14: 664042-tablesort-error-14.patch queued for re-testing.

coltrane’s picture

#14 still applies with offset (bump)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.