Open 9c6a7ad6-d172-4dbc-8581-a815299609c4 opened 5 years ago
Can you please add a reproducible test case and a description to the issue explaining expected behavior and actual behavior?
Thanks
import cookiejar
cookiejar.is_HDN("foo!bar.com")
Output:
True
cookiejar.is_HDN("woo.com.")
Output: False
Test cases taken from:
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.)
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 anis_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
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
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['type-bug', 'library']
title = 'is_HDN is returns false positive and false negative value for two test cases respectively'
updated_at =
user = 'https://bugs.python.org/DivyaRani'
```
bugs.python.org fields:
```python
activity =
actor = 'Divya Rani'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation =
creator = 'Divya Rani'
dependencies = []
files = []
hgrepos = []
issue_num = 35573
keywords = []
message_count = 5.0
messages = ['332404', '332406', '332409', '332413', '332415']
nosy_count = 2.0
nosy_names = ['steven.daprano', 'Divya Rani']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue35573'
versions = ['Python 3.6']
```