dekkerglen / CubeCobra

An open source web application for building, managing, and playtesting Magic the Gathering cubes.
https://www.cubecobra.com
Apache License 2.0
193 stars 120 forks source link

Fix secondary sort error in cube comparisons #2443

Closed lunakv closed 10 months ago

lunakv commented 10 months ago

Fixes #2436.

Issue

The error was caused by the getLabels function being incorrectly passed a whole column instead of an array of cards.

For example, if the primary sort was Color Category and the secondary sort was Guilds, the columns object would end up looking like:

{
    "White": { 
        "Azorius": [...],
        "Boros": [...],
        ...
    },
    "Blue": { ...}
    ...
}

And then the column variable takes on the individual values of that, each of which is an object with guild names as keys (e.g. {"Azorius": [...], "Boros": [...], ...}). Because the getLabels function expects an array of cards and instead got this object, it caused errors, most notably because objects are not iterable and some sort options require iterating over the passed cards.

This also explains why only some tags were affected. Options such as Mana Value only return a predetermined set of labels, so only those options that actually need the list of cards (such as Tags) cause a crash.

Fix

Change the call so that the column is flattened into a simple array of all the cards within it.

lunakv commented 10 months ago

Oh, and I found another bug while debugging this, which I wrote up into #2442