Skip to content
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

Incorrect regex used to match Content-Type #54

Open
slicingmelon opened this issue Oct 29, 2024 · 1 comment
Open

Incorrect regex used to match Content-Type #54

slicingmelon opened this issue Oct 29, 2024 · 1 comment

Comments

@slicingmelon
Copy link
Contributor

Hello,

I've noticed that the current regex used to get the Content-Type is not sufficient to cover all content types.

Current regex:
https://github.com/laluka/bypass-url-parser/blob/main/src/bypass_url_parser/__init__.py#L1495

REGEX_CONTENT_TYPE = re.compile(r"Content-Type:\s+(\w+/\w+)", re.IGNORECASE)

This can be seen in regex101.com too
image

This will lead to empty content-types in the output.

Also, curl sometimes returns the headers case-insensitive, so to fix all these, I suggest the following regex:

(?i)content-type:\s*([-\w.]+/[-\w.]+(?:\s*;\s*[\w-]+=(?:\"[^\"]*\"|[^\s;]*))*)

So, the code would be:

REGEX_CONTENT_TYPE = re.compile(r'(?i)content-type:\s*([-\w.]+/[-\w.]+(?:\s*;\s*[\w-]+=(?:\"[^\"]*\"|[^\s;]*))*)')

Tested in regex101 as well
image

@laluka
Copy link
Owner

laluka commented Oct 29, 2024

Nice catch, I'll have a look with @jtof-fap when we find some free time ! 🌹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants