Thread Tools Display Modes
Prev Previous Post   Next Post Next
09/26/16, 04:17 PM   #1
code65536
AddOn Author - Click to view addons
Join Date: Mar 2016
Posts: 21
[fixed] Faulty code in ZO_SortHeaderGroup:OnHeaderClicked

There is a problem in the ZO_SortHeaderGroup:OnHeaderClicked function (found in \esoui\libraries\zo_sortheadergroup\zo_sortheadergroup.lua), specifically, with the following line of code:

Code:
        self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
The "condition and a or b" shorthand in Lua is subject to one crucial caveat: the "a" term must never be nil or false. If it is, then "b" will always be used, regardless of what "condition" evaluates to.

In this case, since the sort directions are stored as either true or false, this line of code returns the incorrect result if resetSortDir is true and initialDirection is down (false). This code must be replaced with if-then longhand (reversing the condition and swapping a and b will suffer the same problem).

You can see this bug in action if you try to use SelectAndResetSortForKey on a column that has a downward initial sort direction.

(Also, it might be a good idea to audit the code for more instances of these "condition and a or b" shorthands--this is a subtle and easily-missed error, and there could be other places that might have similar problems.)
 
 

ESOUI » Developer Discussions » Bug Reports » [fixed] Faulty code in ZO_SortHeaderGroup:OnHeaderClicked


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off