Sorting URLs improvements #4629

Open
opened 2026-03-04 05:21:23 -05:00 by deekerman · 0 comments
Owner

Originally created by @Fufs on GitHub (Jul 31, 2023).

Prerequisites

  • I have checked the Wiki and Discussions and found no answer

  • I have searched other issues and found no duplicates

  • I want to request a feature or enhancement and not ask a question

The problem

Currently when sorting URLs (say in the DNS rewrites tab), the sorting is done from left to right. This is quite inconvinient as a list of following urls:

  • a.tld
  • b.tld
  • a.b.tld
  • b.a.tld
  • a.b.a.tld

Will be sorted as follows:

  • a.b.a.tld
  • a.b.tld
  • a.tld
  • b.a.tld
  • b.tld

A much better way of sorting would result in the following list:

  • a.tld
  • b.a.tld
  • a.b.a.tld
  • b.tld
  • a.b.tld

Proposed solution

  1. Split the strings by the period symbol ("a.b.a.tld" => ["a", "b", "a", "tld"])
  2. Reverse the list (["a", "b", "a", "tld"] => ["tld", "a", "b", "a"])
  3. Join the elements together with a period (["tld", "a", "b", "a"] => tld.a.b.a)
  4. Sort with those keys
  5. Reverse the steps before displaying the sorted list

This could probably be optimized but that's the general idea.

Alternatives considered and additional information

It is worth noting that IPs should not be sorted this way. Therefore, if a field can contain both IPs and domains, we have to check first if the contents of a cell are and ip address or not (for example with this regex ^((\d|1?[1-9]\d|2[0-4]\d|25[0-5])\.){3}(\d|1?[1-9]\d|2[0-4]\d|25[0-5])$ (have not tested it))

Originally created by @Fufs on GitHub (Jul 31, 2023). ### Prerequisites - [X] I have checked the [Wiki](https://github.com/AdguardTeam/AdGuardHome/wiki) and [Discussions](https://github.com/AdguardTeam/AdGuardHome/discussions) and found no answer - [X] I have searched other issues and found no duplicates - [X] I want to request a feature or enhancement and not ask a question ### The problem Currently when sorting URLs (say in the DNS rewrites tab), the sorting is done from left to right. This is quite inconvinient as a list of following urls: * a.tld * b.tld * a.b.tld * b.a.tld * a.b.a.tld Will be sorted as follows: - a.b.a.tld - a.b.tld - a.tld - b.a.tld - b.tld A much better way of sorting would result in the following list: - a.tld - b.a.tld - a.b.a.tld - b.tld - a.b.tld ### Proposed solution 1. Split the strings by the period symbol ("a.b.a.tld" => ["a", "b", "a", "tld"]) 2. Reverse the list (["a", "b", "a", "tld"] => ["tld", "a", "b", "a"]) 3. Join the elements together with a period (["tld", "a", "b", "a"] => tld.a.b.a) 4. Sort with those keys 5. Reverse the steps before displaying the sorted list This could probably be optimized but that's the general idea. ### Alternatives considered and additional information It is worth noting that IPs should not be sorted this way. Therefore, if a field can contain both IPs and domains, we have to check first if the contents of a cell are and ip address or not (for example with this regex `^((\d|1?[1-9]\d|2[0-4]\d|25[0-5])\.){3}(\d|1?[1-9]\d|2[0-4]\d|25[0-5])$` (have not tested it))
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/AdGuardHome#4629
No description provided.