This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: is_HDN is returns false positive and false negative value for two test cases respectively
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Divya Rani, steven.daprano
Priority: normal Keywords:

Created on 2018-12-24 03:53 by Divya Rani, last changed 2022-04-11 14:59 by admin.

Messages (5)
msg332404 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-24 04:06
Can you please add a reproducible test case and a description to the issue explaining expected behavior and actual behavior?

Thanks
msg332406 - (view) Author: Divya Rani (Divya Rani) Date: 2018-12-24 04:18
import cookiejar

cookiejar.is_HDN("foo!bar.com")
Output:
True

cookiejar.is_HDN("woo.com.")

Output:
False

Test cases taken from:
1. https://github.com/google/guava/blob/581ba1436ebaa54a7f5d0f1db8cc4da0ca72127e/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java#L81
2.
https://github.com/google/guava/blob/581ba1436ebaa54a7f5d0f1db8cc4da0ca72127e/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java#L65
msg332409 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-12-24 05:38
What is the module "cookiejar" you are importing? Is that a third-party module? It doesn't seem to be in the standard library. There is a module `http.cookiejar` but it doesn't seem to have an `is_HDN` function.

If this is a third-party library, please close this and report it to the maintainers of that library.

Can you please explain *why* these are "false positive" and "false negative", and which is which?

In particular, do you know for a fact that the test cases you reference actually pass, and are correct if they pass? I'm not an expert, but I don't think domain names can end with a dot, and the "woo.com." test case is the *only* one which ends with a dot, so I suspect it may be a typo, and the test case doesn't actually pass. (Or if it does pass, perhaps it shouldn't.)
msg332413 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-24 06:02
> What is the module "cookiejar" you are importing? Is that a third-party module? It doesn't seem to be in the standard library. There is a module `http.cookiejar` but it doesn't seem to have an `is_HDN` function.

is_HDN does exist in http.cookiejar [0] which I assume OP is referring to but it's undocumented and used internally in other functions. From the comments and given it was added in 2a6ba9097ee (2004) this may not be as extensive as the guava implementation which I assume is at [1]

IPV4_RE = re.compile(r"\.\d+$", re.ASCII)
def is_HDN(text):
    """Return True if text is a host domain name."""
    # XXX
    # This may well be wrong.  Which RFC is HDN defined in, if any (for
    #  the purposes of RFC 2965)?
    # For the current implementation, what about IPv6?  Remember to look
    #  at other uses of IPV4_RE also, if change this.
    if IPV4_RE.search(text):
        return False
    if text == "":
        return False
    if text[0] == "." or text[-1] == ".":
        return False
    return True

[0]  https://github.com/python/cpython/blob/b7105c9c9663637e4500bfcac75c911e78d9a1c0/Lib/http/cookiejar.py#L521
[1] https://github.com/google/guava/blob/1e072a7922a0b3f7b45b9f53405a233834175177/guava/src/com/google/common/net/InternetDomainName.java#L132
msg332415 - (view) Author: Divya Rani (Divya Rani) Date: 2018-12-24 06:06
The function link is here: https://github.com/python/cpython/blob/e42b705188271da108de42b55d9344642170aa2b/Lib/http/cookiejar.py#L521

The function returned true for "foo!bar.com" which is false positive and the test case is taken from the list of invalid domain names present in Guava test suite https://github.com/google/guava/blob/581ba1436ebaa54a7f5d0f1db8cc4da0ca72127e/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java#L81

Domain names with dots at the end are fully qualified domain names. (reference:
1.https://stackoverflow.com/questions/19480767/domain-names-with-dots-at-the-end#answer-19498025
2. https://en.wikipedia.org/wiki/Fully_qualified_domain_name#Syntax
)
the function returned false for "woo.com." which is a false negative.
The test case is again taken from list of valid domain names provided by guava test suite (https://github.com/google/guava/blob/581ba1436ebaa54a7f5d0f1db8cc4da0ca72127e/android/guava-tests/test/com/google/common/net/InternetDomainNameTest.java#L65)
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79754
2018-12-24 06:06:33Divya Ranisetnosy: - xtreak
messages: + msg332415
2018-12-24 06:02:38xtreaksetnosy: + xtreak
messages: + msg332413
2018-12-24 05:38:50steven.dapranosetnosy: + steven.daprano
messages: + msg332409
2018-12-24 04:18:03Divya Ranisetnosy: - xtreak
messages: + msg332406
2018-12-24 04:06:07xtreaksetnosy: + xtreak
messages: + msg332404
2018-12-24 03:53:06Divya Ranicreate