Skip to content

fix(charset): handle quoted, spaced, and case-insensitive charset values - #794

Open
vmphase wants to merge 3 commits into
lexiforest:mainfrom
vmphase:fix/invalid-regex
Open

fix(charset): handle quoted, spaced, and case-insensitive charset values#794
vmphase wants to merge 3 commits into
lexiforest:mainfrom
vmphase:fix/invalid-regex

Conversation

@vmphase

@vmphase vmphase commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

The current CHARSET_RE only matches unquoted/unspaced/lowercase form of the charset= param, which does not match RFC 9110's grammar.

CHARSET_RE = re.compile(r"charset=([\w-]+)")

CHARSET_RE.search('text/html; charset="utf-8"')   # None
CHARSET_RE.search('text/html; charset = utf-8')   # None
CHARSET_RE.search('text/html; Charset=utf-8')     # None
CHARSET_RE.search('text/html; CHARSET="UTF-8"')   # None

# only this works fine
CHARSET_RE.search('text/html; charset=utf-8')     # <Match: 'utf-8'>  

Checklist

  • I have manually reviewed the changes and fully understand the code.

@lexiforest lexiforest added this to the v0.17 milestone Aug 1, 2026
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

Successfully merging this pull request may close these issues.

2 participants