Skip to content

Modify subdomain sorting#38

Merged
aboul3la merged 1 commit intoaboul3la:masterfrom
jeremyn:modify_subdomain_sorting
Oct 4, 2016
Merged

Modify subdomain sorting#38
aboul3la merged 1 commit intoaboul3la:masterfrom
jeremyn:modify_subdomain_sorting

Conversation

@jeremyn
Copy link
Copy Markdown
Contributor

@jeremyn jeremyn commented Oct 2, 2016

I'm a ruleset reviewer for https://github.com/EFForg/https-everywhere , which is a browser add-on that rewrites some HTTP URLs to HTTPS while the user is browsing. Part of creating rules for HTTPS Everywhere is finding subdomains for a particular root domain. Sublist3r looks like a good tool for this, for example see the discussion in EFForg/https-everywhere#6912 , but we have a particular sort order we like subdomains to have in our ruleset files.

This pull request changes the sort order of the displayed subdomains to match our preferred sort order. You can test it by running the below script in the main Sublist3r directory.

If you want to allow this change but want to hide it behind an optional flag instead of changing the default behavior, or you want tests or style changes, please let me know. Thanks.

import functools
import random
random.seed(0)

from sublist3r import subdomain_cmp


correct_output = [
    'example.com',
    'www.example.com',
    'a.example.com',
    'www.a.example.com',
    'b.a.example.com',
    'b.example.com',
    'example.net',
    'www.example.net',
    'a.example.net',
]

if __name__ == '__main__':
    scrambled_input = correct_output[:]
    random.shuffle(scrambled_input)

    computed_output = sorted(
        scrambled_input,
        key=functools.cmp_to_key(subdomain_cmp),
    )

    print("%s\n" % '\n'.join(['Input:'] + scrambled_input))
    print("%s\n" % '\n'.join(['Output:'] + computed_output))
    print("Output is correct: %s" % (correct_output == computed_output))

@aboul3la
Copy link
Copy Markdown
Owner

aboul3la commented Oct 4, 2016

Thanks @jeremyn for your PR.

I'm glad to know that Sublist3r would be helpful for you to build the rulesets. I'm a big fan of HTTPS Everywhere and i use it myself. So it's a pleasure to support it :)

I really like this type of sorting. It's much better. So I just merged your Pull Request

Thanks again and keep up the great work!

@jeremyn
Copy link
Copy Markdown
Contributor Author

jeremyn commented Oct 4, 2016

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants