Skip to content

Commit

Permalink
some str methods no longer escape their argument
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Sep 15, 2023
1 parent 6e353f9 commit ef4a839
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Unreleased
- Use deferred evaluation of annotations. :pr:`400`
- Update signatures for ``Markup`` methods to match ``str`` signatures. Use
positional-only arguments. :pr:`400`
- Some ``str`` methods on ``Markup`` no longer escape their argument:
``strip``, ``lstrip``, ``rstrip``, ``removeprefix``, ``removesuffix``,
``partition``, and ``rpartition``; ``replace`` only escapes its ``new``
argument. These methods are conceptually linked to search methods such as
``in``, ``find``, and ``index``, which already do not escape their argument.
:issue:`401`


Version 2.1.3
Expand Down
18 changes: 8 additions & 10 deletions src/markupsafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ def upper(self, /) -> te.Self:
return self.__class__(super().upper())

def replace(self, old: str, new: str, count: t.SupportsIndex = -1, /) -> te.Self:
return self.__class__(
super().replace(self.escape(old), self.escape(new), count)
)
return self.__class__(super().replace(old, self.escape(new), count))

def ljust(self, width: t.SupportsIndex, fillchar: str = " ", /) -> te.Self:
return self.__class__(super().ljust(width, self.escape(fillchar)))
Expand All @@ -191,16 +189,16 @@ def rjust(self, width: t.SupportsIndex, fillchar: str = " ", /) -> te.Self:
return self.__class__(super().rjust(width, self.escape(fillchar)))

def lstrip(self, chars: str | None = None, /) -> te.Self:
return self.__class__(super().lstrip(self.escape(chars)))
return self.__class__(super().lstrip(chars))

def rstrip(self, chars: str | None = None, /) -> te.Self:
return self.__class__(super().rstrip(self.escape(chars)))
return self.__class__(super().rstrip(chars))

def center(self, width: t.SupportsIndex, fillchar: str = " ", /) -> te.Self:
return self.__class__(super().center(width, self.escape(fillchar)))

def strip(self, chars: str | None = None, /) -> te.Self:
return self.__class__(super().strip(self.escape(chars)))
return self.__class__(super().strip(chars))

def translate(
self,
Expand All @@ -224,18 +222,18 @@ def casefold(self, /) -> te.Self:
if sys.version_info >= (3, 9):

def removeprefix(self, prefix: str, /) -> te.Self:
return self.__class__(super().removeprefix(self.escape(prefix)))
return self.__class__(super().removeprefix(prefix))

def removesuffix(self, suffix: str) -> te.Self:
return self.__class__(super().removesuffix(self.escape(suffix)))
return self.__class__(super().removesuffix(suffix))

def partition(self, sep: str, /) -> tuple[te.Self, te.Self, te.Self]:
l, s, r = super().partition(self.escape(sep))
l, s, r = super().partition(sep)
cls = self.__class__
return cls(l), cls(s), cls(r)

def rpartition(self, sep: str, /) -> tuple[te.Self, te.Self, te.Self]:
l, s, r = super().rpartition(self.escape(sep))
l, s, r = super().rpartition(sep)
cls = self.__class__
return cls(l), cls(s), cls(r)

Expand Down

0 comments on commit ef4a839

Please sign in to comment.