From 2e0f06e65086f461c20c9fbff89ce821191184f5 Mon Sep 17 00:00:00 2001 From: Sheng Date: Fri, 11 Jan 2019 15:02:30 +0800 Subject: [PATCH] Fixed is_same_primary_domain --- tests/test_utils.py | 4 ++++ webssh/utils.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 24d5ec8..f9007b9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -89,6 +89,10 @@ class TestUitls(unittest.TestCase): domain2 = 'test' self.assertFalse(is_same_primary_domain(domain1, domain2)) + domain1 = 'com' + domain2 = 'example.com' + self.assertFalse(is_same_primary_domain(domain1, domain2)) + domain1 = 'example.com' domain2 = 'example.com' self.assertTrue(is_same_primary_domain(domain1, domain2)) diff --git a/webssh/utils.py b/webssh/utils.py index 6e89551..59f0735 100644 --- a/webssh/utils.py +++ b/webssh/utils.py @@ -103,9 +103,9 @@ def is_same_primary_domain(domain1, domain2): dots = 0 l1 = len(domain1) l2 = len(domain2) - m = 0 - min(l1, l2) + m = min(l1, l2) - while i >= m: + while i >= -m: c1 = domain1[i] c2 = domain2[i] @@ -122,5 +122,8 @@ def is_same_primary_domain(domain1, domain2): if l1 == l2: return True + if dots == 0: + return False + c = domain1[i] if l1 > m else domain2[i] return c == '.'