-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
gh-87112: Ensure that only digits convertible to integers are accepted as section number in MIME header parameter #136877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
ff4ca5c
656b6fb
75636a5
b15c404
7cba42f
d2d59ee
54bbbb7
f12e424
b364339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2398,22 +2398,19 @@ def get_section(value): | |||||
The caller should already have dealt with leading CFWS. | ||||||
|
||||||
""" | ||||||
def is_allowed_digit(c): | ||||||
# We don't use str.isdigit because only 0-9 are accepted, not | ||||||
# super-script and other types of digits. | ||||||
return c in {'0','1','2','3','4','5','6','7','8','9'} | ||||||
|
||||||
section = Section() | ||||||
if not value or value[0] != '*': | ||||||
raise errors.HeaderParseError("Expected section but found {}".format( | ||||||
value)) | ||||||
section.append(ValueTerminal('*', 'section-marker')) | ||||||
value = value[1:] | ||||||
if not value or not is_allowed_digit(value[0]): | ||||||
# We don't use str.isdigit because only 0-9 are accepted, not super-script | ||||||
# and other types of digits. | ||||||
if not value or not '0' <= value[0] <= '9': | ||||||
raise errors.HeaderParseError("Expected section number but " | ||||||
"found {}".format(value)) | ||||||
digits = '' | ||||||
while value and is_allowed_digit(value[0]): | ||||||
while value and '0' <= value[0] <= '9': | ||||||
|
while value and '0' <= value[0] <= '9': | |
while value and ('0' <= value[0] <= '9'): |
It will a bit clearer. Or you can still use a separate function to make it even cleareer. The bottleneck won't be the function call IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that, but not the separate function. It was my understanding that @StanFromIreland was leaning towards not having an inner function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, I was against the function to check if it is in a dictionary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Just moved it to a separate function for extra-clarity
Uh oh!
There was an error while loading. Please reload this page.