Skip to content

Don't raise from parse() on entity backslashes, out-of-range character references, or non-numeric EPSG codes - #600

Closed
DrVelvetFog wants to merge 1 commit into
kurtmckee:mainfrom
DrVelvetFog:fix-parse-raises
Closed

DrVelvetFog wants to merge 1 commit into
kurtmckee:mainfrom
DrVelvetFog:fix-parse-raises

Conversation

@DrVelvetFog

Copy link
Copy Markdown

Fixes three of the cases in #599:

  • sanitizer.replace_doctype(): pass the rebuilt entity declarations to RE_DOCTYPE_PATTERN.sub() through a function, so backslashes in entity values aren't read as escapes or group references. Before, C:\data raised re.PatternError, C:\temp turned into a tab, and \1 pulled in DOCTYPE text.
  • mixin.handle_charref(): map character references above U+10FFFF, and surrogates, to U+FFFD (what HTML parsers do) instead of raising from chr() / .encode().
  • namespaces/georss.py: if the EPSG code in srsName isn't an integer, treat it like a missing srsName instead of raising from int(). The check that was duplicated in _end_gml_pos and _end_gml_poslist is now one helper.

Tests, in the existing data-driven format:

  • tests/wellformed/rss/entity_in_doctype_backslash.xml: C:\data\1\new comes through unchanged
  • tests/illformed/charref_out_of_range.xml: �, � and � become U+FFFD
  • tests/wellformed/geo/gml_point_epsg_not_numeric.xml: srsName="EPSG:unknown" parses like a point with no srsName

All three fail without the change (5 failures across the strict and loose parsers). The full suite passes: 4302 passed, 8 skipped. black and isort are clean. Changelog fragment added under "Fixed".

@kurtmckee

Copy link
Copy Markdown
Owner

This seems to be generated by AI. Closing.

@kurtmckee kurtmckee closed this Sep 22, 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