diff --git a/CHANGELOG.md b/CHANGELOG.md index abe5cc0f7..ba8bb13d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ## Unreleased: mitmproxy next +- Fix contentview detection for XML files that start with CRLF. + ([#8243](https://github.com/mitmproxy/mitmproxy/pull/8243), @ADiTyaRaj8969) - mitmweb: Fix the filter input losing half-typed text on unrelated parent re-renders. ([#8234](https://github.com/mitmproxy/mitmproxy/pull/8234), @ariel42) - mitmweb: Fix an infinite update cycle in `FlowTable` by only recomputing the virtual-scroll window in `componentDidUpdate` when `flowView` or `rowHeight` actually change. diff --git a/mitmproxy/utils/strutils.py b/mitmproxy/utils/strutils.py index 9c5cb7273..00577277f 100644 --- a/mitmproxy/utils/strutils.py +++ b/mitmproxy/utils/strutils.py @@ -163,8 +163,10 @@ def is_mostly_bin(s: bytes) -> bool: def is_xml(s: bytes) -> bool: + # XML 1.0 §2.3 defines whitespace as (#x20 | #x9 | #xD | #xA), so a + # leading \r before "<" should also be skipped here. for char in s: - if char in (9, 10, 32): # is space? + if char in (9, 10, 13, 32): # is whitespace? continue return char == 60 # is a "<"? return False diff --git a/test/mitmproxy/utils/test_strutils.py b/test/mitmproxy/utils/test_strutils.py index 0a3c9f95d..dea991ae6 100644 --- a/test/mitmproxy/utils/test_strutils.py +++ b/test/mitmproxy/utils/test_strutils.py @@ -106,6 +106,11 @@ def test_is_xml(): assert not strutils.is_xml(b"foo") assert strutils.is_xml(b"