You are right, I saw the agreed way of parsing in RFC6265[1], it seems that you should not use regular expressions.
I used http.cookiejar to update the code, but it failed to pass the test: https://github.com/python/cpython/blob/master/Lib/test/test_http_cookies.py#L19. However, other languages and libraries (JavaScript, Requests, http.cookiejar, etc.) cannot parse it. It seems that the contents of the brackets should be escaped. Is this a wrong test case?
I updated the code[2] using http.cookiejar. Is this a good idea?
English is not my native language; please excuse typing errors.
[1] https://tools.ietf.org/html/rfc6265
[2] https://github.com/python/cpython/pull/11665/commits/a03bc75348a4041c7411da3175689c087a98789f |