Repository: carsonyl/pypac

Issue:
Doesn't accept `https://antizapret.prostovpn.org/proxy.pac` as valid script
It raises `_dukpy.JSRuntimeError: EvalError: Error while calling Python Function: TypeError('inet_aton() argument 1 must be str, not bool')` when testing `self.find_proxy_for_url("/", "0.0.0.0")`. Removing the check locally allows the file to be correctly consumed by my code. Note that my other issue needs to be resolved before you could use the URL as is, or manually follow the redirect and use the end URL when working with the PAC file.

Comments:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 6c79d4d..8c0c6a0 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,3 +1,11 @@
+0.16.2 (2023-03-26)
+-------------------
+
+- Handle boolean args to ``isInNet()``. (#69)
+- Remove Python 3.5, 3.6 from CIB test matrix.
+- Windows Python 2.7 CIB: Pin to dukpy 0.2.3.
+
+
 0.16.1 (2022-11-08)
 -------------------
 
diff --git a/pypac/__init__.py b/pypac/__init__.py
index c66b7a1..5fe422d 100644
--- a/pypac/__init__.py
+++ b/pypac/__init__.py
@@ -1,26 +1,31 @@
-"""
-PyPAC: Proxy auto-config for Python
-===================================
-
-Copyright 2018 Carson Lam
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-"""
-
-from pypac.api import get_pac, collect_pac_urls, download_pac, PACSession, pac_context_for_url
-
-
-__version__ = "0.16.1"
-
-
-__all__ = ["get_pac", "collect_pac_urls", "download_pac", "PACSession", "pac_context_for_url"]
+"""
+PyPAC: Proxy auto-config for Python
+===================================
+
+Copyright 2018 Carson Lam
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+from pypac.api import (
+    PACSession,
+    collect_pac_urls,
+    download_pac,
+    get_pac,
+    pac_context_for_url,
+)
+
+__version__ = "0.16.2"
+
+
+__all__ = ["get_pac", "collect_pac_urls", "download_pac", "PACSession", "pac_context_for_url"]
diff --git a/pypac/parser_functions.py b/pypac/parser_functions.py
index 9b92a6d..ca3f813 100644
--- a/pypac/parser_functions.py
+++ b/pypac/parser_functions.py
@@ -58,6 +58,9 @@ def isInNet(host, pattern, mask):
     :returns: True iff the IP address of the host matches the specified IP address pattern.
     :rtype: bool
     """
+    host = str(host)
+    pattern = str(pattern)
+    mask = str(mask)
     host_ip = host if is_ipv4_address(host) else dnsResolve(host)
     if not host_ip or not is_ipv4_address(pattern) or not is_ipv4_address(mask):
         return False


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 33a715d..adcdb6a 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -12,7 +12,7 @@ jobs:
     strategy:
       matrix:
         os: [ubuntu-latest, macos-latest, windows-latest]
-        python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10', 3.11]
+        python-version: [2.7, 3.7, 3.8, 3.9, '3.10', 3.11]
 
     steps:
     - uses: actions/checkout@v3
@@ -20,6 +20,10 @@ jobs:
       uses: actions/setup-python@v4
       with:
         python-version: ${{ matrix.python-version }}
+    - name: Install dukpy for Windows Python 2.7
+      if: matrix.os == 'windows-latest' && matrix.python-version == '2.7'
+      # Pin to final release that still published Python 2.7 binary wheels
+      run: pip install dukpy==0.2.3
     - name: Install dependencies
       run: |
         python -m pip install --upgrade pip setuptools
diff --git a/tests/test_parser_functions.py b/tests/test_parser_functions.py
index a5b0388..d476958 100644
--- a/tests/test_parser_functions.py
+++ b/tests/test_parser_functions.py
@@ -1,25 +1,26 @@
-import pytest
 from datetime import datetime
 
+import pytest
+
 try:
     from unittest.mock import patch
 except ImportError:
-    from mock import patch
+    from mock import patch  # noqa
 
 from pypac.parser_functions import (
+    alert,
+    dateRange,
     dnsDomainIs,
-    isResolvable,
-    isInNet,
-    dnsResolve,
     dnsDomainLevels,
-    weekdayRange,
-    myIpAddress,
+    dnsResolve,
+    isInNet,
     isPlainHostName,
+    isResolvable,
+    localHostOrDomainIs,
+    myIpAddress,
     shExpMatch,
     timeRange,
-    localHostOrDomainIs,
-    dateRange,
-    alert,
+    weekdayRange,
 )
 
 
@@ -55,6 +56,7 @@ def test_isResolvable(host, expected_value):
         ("192.168.1.100", "192.168.2.0", "255.255.255.0", False),
         ("google.com", "0.0.0.0", "0.0.0.0", True),
         ("google.com", "google.com", "foo", False),
+        (False, False, False, False),
     ],
 )
 def test_isInNet(host, pattern, mask, expected_value):