Skip to content

Commit

Permalink
The sorting had ensured that sections with the tag catch-plain-hostna…
Browse files Browse the repository at this point in the history
…mes were prioritized. This should only happen if there are no destinations in the section, otherwise the hostname overlap check will no longer help.
  • Loading branch information
73h committed Sep 17, 2024
1 parent c36273f commit d2dcd9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "paccreator"
version = "0.2.1"
version = "0.2.2"
dynamic = ["dependencies"]
authors = [
{ name = "Heiko Schmidt", email = "73h@gmx.net" },
Expand Down
4 changes: 3 additions & 1 deletion src/paccreator/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ def get_target_type(target: str) -> TargetType:


def sort_by_rating(proxy):
return min([t.rating for t in proxy.targets])
if len(proxy.targets) == 1 and TargetType.PLAIN_HOSTNAME in [t.type for t in proxy.targets]:
return TargetType.PLAIN_HOSTNAME.value;
return min([t.rating for t in proxy.targets if t.type != TargetType.PLAIN_HOSTNAME])
16 changes: 16 additions & 0 deletions src/tests/helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,19 @@ def test_sort_by_rating(self):
self.assertEqual(config.proxies[0].targets[0].rating, 4)
config.proxies.sort(key=sort_by_rating)
self.assertEqual(config.proxies[0].route, "B")

def test_sort_by_rating_with_plain_hostname_tag(self):
config = {"proxies": [{"route": "A", "tags": ["catch-plain-hostnames"], "targets": [".example.com"]},
{"route": "B", "targets": ["foo.example.com"]}]}
config = PacCreatorConfig(**config)
config.recognize_overlaps()
config.proxies.sort(key=sort_by_rating)
self.assertEqual(config.proxies[0].route, "B")

def test_sort_by_rating_with_plain_hostname_tag_in_exclusive_section(self):
config = {"proxies": [{"route": "A", "tags": ["catch-plain-hostnames"], "targets": []},
{"route": "B", "targets": ["foo.example.com"]}]}
config = PacCreatorConfig(**config)
config.recognize_overlaps()
config.proxies.sort(key=sort_by_rating)
self.assertEqual(config.proxies[0].route, "A")

0 comments on commit d2dcd9f

Please sign in to comment.