From a75493d48d971ad5f0858abb25c7e6598deb560f Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 5 Jul 2021 01:23:15 +0300
Subject: [PATCH] Let .with_name() and .with_suffix() handle Unicode strings.

---
 pathlib2/__init__.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pathlib2/__init__.py b/pathlib2/__init__.py
index d5a47a6..f1252e0 100644
--- a/pathlib2/__init__.py
+++ b/pathlib2/__init__.py
@@ -1077,7 +1077,7 @@ class PurePath(object):
                 or drv or root or len(parts) != 1):
             raise ValueError("Invalid name %r" % (name))
         return self._from_parsed_parts(self._drv, self._root,
-                                       self._parts[:-1] + [name])
+                                       self._parts[:-1] + parts[-1:])
 
     def with_suffix(self, suffix):
         """Return a new path with the file suffix changed.  If the path
@@ -1090,6 +1090,11 @@ class PurePath(object):
             raise ValueError("Invalid suffix %r" % (suffix))
         if suffix and not suffix.startswith('.') or suffix == '.':
             raise ValueError("Invalid suffix %r" % (suffix))
+
+        if six.PY2 and not isinstance(suffix, str) and isinstance(suffix, six.text_type):
+            # see _parse_args() above
+            suffix = suffix.encode(sys.getfilesystemencoding() or "ascii")
+
         name = self.name
         if not name:
             raise ValueError("%r has an empty name" % (self,))
-- 
2.30.2

