GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-102988: Detect email address parsing errors and return empty tuple to indicate the parsing error (old API) by tdwyer · Pull Request #102990 · python/cpython Conversation
Contributor
Pull Request titlegh-102988: This PR is designed to detect parsing errors and return an empty tuple to indicate the parsing error. Additionally, this PR updates the I realize that this PR dose not actually track down the bug and fix it. It simply detects the error has happened and returns a parsing error. However,
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for v in fieldvalues: | ||
| s = str(v).replace('\\(', '').replace('\\)', '') | ||
| if s.count('(') != s.count(')'): | ||
| fieldvalues.remove(v) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this loop is modifying the apparent list it is iterating over within the loop. that makes reasoning about its exact behavior hard. removing an item could mean you wind up skipping an item, appending an item could make the loop iterate over that. furthermore remove is O(n)... you're re-finding the item to remove to remove it. Also, this code modifys the passed in list in place before returning it.
A better code pattern for this is to build up a new list and return that. never modifying the input.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Something like:
accepted_values = [] for v in fieldvalues: s = v.replace('\\(', '').replace('\\)', '') if s.count('(') != s.count(')'): v = ('', '') accepted_values.append(v) return accepted_values
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| """Validate the parsed values are syntactically correct""" | ||
| for v in parsedvalues: | ||
| if '[' in v[1]: | ||
| parsedvalues.remove(v) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
same design comment as above, don't modify the list being iterated over and don't modify the argument in place.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| n = 0 | ||
| for v in fieldvalues: | ||
| n += str(v).count(',') + 1 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
get rid of this str(v)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def getaddresses(fieldvalues): | ||
| """Return a list of (REALNAME, EMAIL) for each fieldvalue.""" | ||
| fieldvalues = _pre_parse_validation(fieldvalues) | ||
| all = COMMASPACE.join(str(v) for v in fieldvalues) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The existing code already calls str(v) here... this is a problem. It means the input can be anything. But we probably cannot change it in a patch release for a security fix.
To avoid propagating this mistake into more lines of code spread out, I suggest changing this function to do:
fieldvalues = [str(v) for v in fieldvalues]
on the first line and get rid of all subsequent str(v) calls on anything from fieldvalues in this function or in functions it calls.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| def getaddresses(fieldvalues): | ||
| """Return a list of (REALNAME, EMAIL) for each fieldvalue.""" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
add documentation mentioning that fieldvalues that could not be parsed may cause a ('', '') item to be returned in their place.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def _pre_parse_validation(fieldvalues): | ||
| """Validate the field values are syntactically correct""" | ||
| for v in fieldvalues: | ||
| s = str(v).replace('\\(', '').replace('\\)', '') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
See later comments on str(v) being bad, we can get rid of it here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return address | ||
|
|
||
|
|
||
| def _pre_parse_validation(fieldvalues): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the name "fieldvalues" is non-specific. i realize it comes from the name in getaddress() but we should make it more clear what these are. email_address_fields perhaps?
Related: I don't this docstring adds meaningful value. naming the function and parameter right along with it being short code is sufficiently self explanatory for this internal function. get rid of the docstring.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def _post_parse_validation(parsedvalues): | ||
| """Validate the parsed values are syntactically correct""" | ||
| for v in parsedvalues: | ||
| if '[' in v[1]: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Add a comment explaining why only [ is not allowed. ideally with a link to the relevant RFC or similar.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return fieldvalues | ||
|
|
||
|
|
||
| def _post_parse_validation(parsedvalues): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
parsed_email_address_tuples perhaps?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
stylistic suggestions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.getaddresses(['[email protected](<[email protected]>']), | ||
| [('', '')]) | ||
| eq(utils.getaddresses(['[email protected])<[email protected]>']), | ||
| [('' ,'')]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| [('' ,'')]) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.getaddresses(['[email protected])<[email protected]>']), | ||
| [('' ,'')]) | ||
| eq(utils.getaddresses(['[email protected]<<[email protected]>']), | ||
| [('' ,'')]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| [('' ,'')]) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.getaddresses(['[email protected]<<[email protected]>']), | ||
| [('' ,'')]) | ||
| eq(utils.getaddresses(['[email protected]><[email protected]>']), | ||
| [('' ,'')]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| [('' ,'')]) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.getaddresses(['[email protected]><[email protected]>']), | ||
| [('' ,'')]) | ||
| eq(utils.getaddresses(['[email protected]@<[email protected]>']), | ||
| [('' ,'')]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| [('' ,'')]) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.getaddresses(['[email protected],<[email protected]>']), | ||
| [('', '[email protected]'), ('', '[email protected]')]) | ||
| eq(utils.getaddresses(['[email protected];<[email protected]>']), | ||
| [('' ,'')]) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| [('' ,'')]) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.parseaddr(['[email protected];<[email protected]>']), | ||
| ('' ,'')) | ||
| eq(utils.parseaddr(['[email protected]:<[email protected]>']), | ||
| ('' ,'')) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ('' ,'')) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.parseaddr(['[email protected]:<[email protected]>']), | ||
| ('' ,'')) | ||
| eq(utils.parseaddr(['[email protected].<[email protected]>']), | ||
| ('' ,'')) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ('' ,'')) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.parseaddr(['[email protected].<[email protected]>']), | ||
| ('' ,'')) | ||
| eq(utils.parseaddr(['[email protected]"<[email protected]>']), | ||
| ('' ,'')) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ('' ,'')) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.parseaddr(['[email protected]"<[email protected]>']), | ||
| ('' ,'')) | ||
| eq(utils.parseaddr(['[email protected][<[email protected]>']), | ||
| ('' ,'')) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ('' ,'')) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| eq(utils.parseaddr(['[email protected][<[email protected]>']), | ||
| ('' ,'')) | ||
| eq(utils.parseaddr(['[email protected]]<[email protected]>']), | ||
| ('' ,'')) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ('' ,'')) | |
| [('', '')]) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
You could use Core developers can help to remove the redundant requests for review. Before that you may need to force push the correct commits, or close this PR and start a new one. :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm going to have to make a new PR... Git is all messed up now... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gpshead @CharlieZhao95 @theta682 I had to create a new PR because I messed up Git when trying to push the changes #105127 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.