Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify subdomain sorting #38

Merged
merged 1 commit into from
Oct 4, 2016
Merged

Modify subdomain sorting #38

merged 1 commit into from
Oct 4, 2016

Conversation

jeremyn
Copy link
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
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
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