diff --git a/gunicorn/util.py b/gunicorn/util.py index 456267a1..8aa441d0 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -21,6 +21,7 @@ import inspect import errno import warnings import logging +import re from gunicorn import _compat from gunicorn.errors import AppImportError @@ -232,11 +233,8 @@ def is_ipv6(addr): def parse_address(netloc, default_port=8000): - if netloc.startswith("unix://"): - return netloc.split("unix://")[1] - - if netloc.startswith("unix:"): - return netloc.split("unix:")[1] + if re.match(r'unix:(//)?', netloc): + return re.split(r'unix:(//)?', netloc)[-1] if netloc.startswith("tcp://"): netloc = netloc.split("tcp://")[1] diff --git a/tests/test_util.py b/tests/test_util.py new file mode 100644 index 00000000..fbd0aa21 --- /dev/null +++ b/tests/test_util.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 - +# +# This file is part of gunicorn released under the MIT license. +# See the NOTICE for more information. + +from gunicorn import util + + +def test_parse_address(): + # Test unix socket addresses (PR #1623) + assert util.parse_address('unix://var/run/test.sock') == 'var/run/test.sock' + assert util.parse_address('unix:/var/run/test.sock') == '/var/run/test.sock'