From 7add29c77b088299841e1017a7cd2f96133a6659 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 8 Oct 2024 09:16:25 -0700 Subject: [PATCH] fix exact str check --- CHANGES.rst | 1 + src/markupsafe/__init__.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3c72a796..941fcd7c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Version 3.0.1 Unreleased - Address compiler warnings that became errors in GCC 14. :issue:`466` +- Fix compatibility with proxy objects. :issue:`467` Version 3.0.0 diff --git a/src/markupsafe/__init__.py b/src/markupsafe/__init__.py index 0afddc0c..fee8dc7a 100644 --- a/src/markupsafe/__init__.py +++ b/src/markupsafe/__init__.py @@ -34,7 +34,9 @@ def escape(s: t.Any, /) -> Markup: """ # If the object is already a plain string, skip __html__ check and string # conversion. This is the most common use case. - if s.__class__ is str: + # Use type(s) instead of s.__class__ because a proxy object may be reporting + # the __class__ of the proxied value. + if type(s) is str: return Markup(_escape_inner(s)) if hasattr(s, "__html__"):