diff --git a/filter/osa-filters.py b/filter/osa-filters.py index d624a520..0a241811 100644 --- a/filter/osa-filters.py +++ b/filter/osa-filters.py @@ -183,8 +183,14 @@ def get_netloc_no_port(url): :type url: ``str`` :returns: ``str`` """ - return get_netloc(url=url).split(':')[0] - + try: + hostname = urlparse(url).hostname + except Exception as exp: + raise errors.AnsibleFilterError( + 'Failed to return the hostname of: "%s"' % str(exp) + ) + else: + return hostname def get_netorigin(url): """Return the netloc from a URL. diff --git a/tests/test-filters.yml b/tests/test-filters.yml index 5ef9bf3a..c5da9974 100644 --- a/tests/test-filters.yml +++ b/tests/test-filters.yml @@ -30,12 +30,14 @@ set_fact: url_netloc: "{{ 'http://review.openstack.org:29418/something' | netloc }}" url_netloc_no_port: "{{ 'http://review.openstack.org:29418/something' | netloc_no_port }}" + url_netloc_no_port_with_auth: "{{ 'http://user:secrete@review.openstack.org:29418/something' | netloc_no_port }}" url_netorigin: "{{ 'http://review.openstack.org:29418/something' | netorigin }}" - name: Validate net filters assert: that: - "url_netloc == 'review.openstack.org:29418'" - "url_netloc_no_port == 'review.openstack.org'" + - "url_netloc_no_port_with_auth == 'review.openstack.org'" - "url_netorigin == 'http://review.openstack.org:29418'" - name: Validate string_2_int filter