Last modified: 2013-10-23 18:17:05 UTC
Colums in the IP/CIDR format to not sort properly in class="wikitable sortable" tables. IPs sort correctly, (apparently using numeric sort, which is nice.) {| class="wikitable sortable" ! A !! IP |- | errata-prod || 25.71.30.0 |- | errata-test || 25.71.31.0 |- | Satellite || 25.71.32.0 |- | foobar || 25.23.33.0 |- | AD3 || 25.71.33.0 |- | AD3 FOO || 25.71.34.0 |- | zfs || 192.168.151.0 |} Upon sorting by IP, we get a table like this (Text Rendered here) +-------------+--------------- ! A ! IP ^ +-------------+--------------- | foobar | 25.23.33.0 | errata-prod | 25.71.30.0 | errata-test | 25.71.31.0 | Satellite | 25.71.32.0 | AD3 | 25.71.33.0 | AD3 FOO | 25.71.34.0 | zfs | 192.168.151.0 However when we add the CIDR mask to the IPs, the table does not sort correctly. {| class="wikitable sortable" ! A !! IP |- | errata-prod || 25.71.30.0/24 |- | errata-test || 25.71.31.0/24 |- | Satellite || 25.71.32.0/24 |- | foobar || 25.23.33.0/24 |- | AD3 || 25.71.33.0/24 |- | AD3 FOO || 25.71.34.0/24 |- | zfs || 192.168.151.0/24 |} Sorting by IP gives +-------------+--------------- ! A ! IP ^ +-------------+--------------- | errata-prod | 25.71.30.0/24 | errata-test | 25.71.31.0/24 | Satellite | 25.71.32.0/24 | foobar | 25.23.33.0/24 | AD3 | 25.71.33.0/24 | AD3 FOO | 25.71.34.0/24 | zfs | 192.168.151.0/24 Which is incorrect, 'foobar' is not where is should be. It appears to be sorted by the third decimal octet which is confirmed by changing the foobar value to '25.23.47.0/24' Which gives the 'sorted' table +-------------+----------------- ! A ! IP ^ +-------------+----------------- | errata-prod | 25.71.30.0/24 | errata-test | 25.71.31.0/24 | Satellite | 25.71.32.0/24 | AD3 | 25.71.33.0/24 | AD3 FOO | 25.71.34.0/24 | foobar | 25.23.47.0/24 | zfs | 192.168.151.0/24 Changing the CIDR mask doesn't change the outcome +-------------+----------------- ! A ! IP ^ +-------------+----------------- | errata-prod | 25.71.30.0/16 | errata-test | 25.71.31.0/16 | Satellite | 25.71.32.0/16 | AD3 | 25.71.33.0/16 | AD3 FOO | 25.71.34.0/24 | foobar | 25.23.47.0/16 | zfs | 192.168.151.0/24 EXPECTED OUTCOME: Table Sorted by IP/CIDR should output the rows in the same order as IP alone. +-------------+----------------- ! A ! IP ^ +-------------+----------------- | foobar | 25.23.47.0/16 | errata-prod | 25.71.30.0/16 | errata-test | 25.71.31.0/16 | Satellite | 25.71.32.0/16 | AD3 | 25.71.33.0/16 | AD3 FOO | 25.71.34.0/24 | zfs | 192.168.151.0/24
The autodetection filter will detect this as IPAddresses and sort it like these, but IP/CIDR is not supported by the auto detection, causing unexpected behavior. The proper solution here is to add CIDR support, or to enforce IP sorting by using "data-sort-type='IPAddress'" on the column. Problem is though that WMF wiki's still haven't enable HTML5 mode, making the latter option impossible.
it matches one of the 3 'date' regexes in autodetect mode to be exact...
Added support for CIDR notation in r111829
Thanks so much for the fix. Minor issue with it. The /xx value in the test cases are greater than the max number of bits in the IP address, which is 32. Also, the regexp looks for 1-3 digits in the /xx portion. Valid values would be 1-32. These observations do not affect the correctness of the solution, but it may be prudent to minimize overlay with other formats.
reverted
I won't be reapplying this change btw, the requested complexity is too much. It has turned from 'accept CIDR notation" into "handle CIDR notation in sort algorithm". Turning it from a 1 hour patch into a multi hour exercise in math and efficiency, for which I do not have the time.
Adding myself in CC as a reminder. Will probably finish the implementation post git migration.
This will fix itself if bug 45161 is solved.