From 5470f7a42dfd3307cd204ab42c315b729267b186 Mon Sep 17 00:00:00 2001 From: Paik Paustian Date: Wed, 22 Dec 2021 14:27:55 +0100 Subject: [PATCH] Fix IP address sorting when there are empty entries in the table When a table contains empty values, sorting by IP addresses using the `ip-address.js` sorting plugin caused erratic sorting behaviour. The empty lines are not sorted correctly and remain scattered about the rest of the rows. This seems to be due to a type issue: The ip-address sorting plugin has a guard-clause if-statement that checks if the value that is to be sorted is false-y. In that case, the integer `0` is returned. The function seems to usually normalise ip addresses to a lexicographically sortable format, and values like `"86b4b93fbbf0418144b55bc45057b720"` and `"173040030054"` are returned. The resulting comparison between strings and integers seems to cause misplaced empty rows and all-over weird sorting behaviour. This commit changes the value returned by the guard-clause to the string value `"000000000000"`, which is simliar to the normalized IPv4 format already used by the plugin. --- sorting/ip-address.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/ip-address.js b/sorting/ip-address.js index c06f9f6..4441b35 100644 --- a/sorting/ip-address.js +++ b/sorting/ip-address.js @@ -25,7 +25,7 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { var x, xa; if (!a) { - return 0 + return '000000000000'; } a = a.replace(/<[\s\S]*?>/g, "");