Skip to content

Conversation

@timb07
Copy link
Contributor

@timb07 timb07 commented Jul 22, 2017

In email._header_value_parser.DisplayName(), ensure we're dealing with a TokenList before trying to access its token_type attribute. This scenario is encountered when parsing a display name starting with a dot (".") or ending with a dot and without whitespace separating it from the angle bracket starting the address.

Add tests to confirm.

https://bugs.python.org/issue30988

@mention-bot
Copy link

@timb07, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bitdancer, @ezio-melotti and @serhiy-storchaka to be potential reviewers.


def test_complex_address_list(self):
examples = list(self.example_params.values())
examples = list(self.example_params.values())[:-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not future proof. What if someone adds new tests? In fact, you are just hidding that name_starting_with_dot is not passing the test:

ERROR: test_complex_address_list (test.test_email.test_headerregistry.TestAddressHeader)
----------------------------------------------------------------------
Traceback (most recent call last):
File "Lib/email/_header_value_parser.py", line 1907, in get_address
    token, value = get_group(value)
File "Lib/email/_header_value_parser.py", line 1866, in get_group
    "display name but found '{}'".format(value))
email.errors.HeaderParseError: expected ':' at end of group display name but found '<jxd@example.com>'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "Lib/test/test_email/test_headerregistry.py", line 1284, in test_complex_address_list
    h = self.make_header('to', source)
File "Lib/test/test_email/test_headerregistry.py", line 78, in make_header
    return self.factory(name, value)
File "Lib/email/headerregistry.py", line 589, in __call__
    return self[name](name, value)
File "Lib/email/headerregistry.py", line 197, in __new__
    cls.parse(value, kwds)
File "Lib/email/headerregistry.py", line 340, in parse
    kwds['parse_tree'] = address_list = cls.value_parser(value)
File "Lib/email/headerregistry.py", line 331, in value_parser
    address_list, value = parser.get_address_list(value)
File "Lib/email/_header_value_parser.py", line 1930, in get_address_list
    token, value = get_address(value)
File "Lib/email/_header_value_parser.py", line 1910, in get_address
    token, value = get_mailbox(value)
File "Lib/email/_header_value_parser.py", line 1733, in get_mailbox
    token, value = get_name_addr(value)
File "Lib/email/_header_value_parser.py", line 1716, in get_name_addr
    token[0][:0] = [leader]
TypeError: 'ValueTerminal' object does not support item assignment

I think you should try to fix this one too :)

@BoboTiG
Copy link
Contributor

BoboTiG commented Jul 30, 2018

Thanks for the patch!

Could you add the NEWs entry as well please?

@maxking maxking changed the title bpo-30988 Fix parsing address headers with dots start/end display name bpo-30988: Fix parsing address headers with dots start/end display name Aug 31, 2019
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 20, 2022
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jul 29, 2022
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Aug 29, 2022
@arhadthedev
Copy link
Member

@timb07 This abandoned PR will be closed in a few weeks if the reviews will not be addressed or at least commented.

@arhadthedev arhadthedev added the pending The issue will be closed if no feedback is provided label Feb 5, 2023
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Feb 6, 2023
@arhadthedev arhadthedev changed the title bpo-30988: Fix parsing address headers with dots start/end display name gh-75171: Fix parsing address headers with dots start/end display name Mar 4, 2023
@arhadthedev
Copy link
Member

OP did not allow to push into the PR branch do I can neither try to fix the PR nor even use the web interface to merge main into fix-issue-30988 and trigger the CLA check.

@timb07 Could you address the review please? It would be great to see this PR merged.

@arhadthedev
Copy link
Member

For the NEWS entry, you can create the following Misc/NEWS.d/next/Library/2023-03-04-23-16-05.gh-issue-75171.0_sIEj.rst text file:

Fix parsing :mod:`email` address headers with dots start/end display name.
Patch by Tim Bell.

@arhadthedev
Copy link
Member

@timb07 You can ping me to reopen this pull request if/when you want to continue your work here.

Closing as abandoned and unrecoverable:

  • The PR branch is closed from external pushes so nobody can commit missing bits

  • The OP did not react to recent notifications 55 and 28 days ago

  • ... while having activity in private repos so the notifications were not sent into the void:

@arhadthedev arhadthedev closed this Apr 1, 2023
@AA-Turner AA-Turner removed the pending The issue will be closed if no feedback is provided label Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants