Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dded848

Browse files
committed
Allow unicode pathnames where FSRefs are expected. Fixes 696253.
1 parent d65ec37 commit dded848

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lib/test/test_macfs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def test_fsspec(self):
2626
def test_fsref(self):
2727
fsr = macfs.FSRef(test_support.TESTFN)
2828
self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname())
29+
30+
def test_fsref_unicode(self):
31+
testfn_unicode = unicode(test_support.TESTFN)
32+
fsr = macfs.FSRef(testfn_unicode)
33+
self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname())
2934

3035
def test_coercion(self):
3136
fss = macfs.FSSpec(test_support.TESTFN)

Mac/Modules/file/_Filemodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,8 +3222,11 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
32223222

32233223
#if TARGET_API_MAC_OSX
32243224
/* On OSX we now try a pathname */
3225-
if ( PyString_Check(v) ) {
3226-
if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
3225+
if ( PyString_Check(v) || PyUnicode_Check(v)) {
3226+
char *path = NULL;
3227+
if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
3228+
return NULL;
3229+
if ( (err=FSPathMakeRef(path, fsr, NULL)) ) {
32273230
PyMac_Error(err);
32283231
return 0;
32293232
}

Mac/Modules/file/filesupport.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ def getargsCheck(self, name):
280280
281281
#if TARGET_API_MAC_OSX
282282
/* On OSX we now try a pathname */
283-
if ( PyString_Check(v) ) {
284-
if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
283+
if ( PyString_Check(v) || PyUnicode_Check(v)) {
284+
char *path = NULL;
285+
if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
286+
return NULL;
287+
if ( (err=FSPathMakeRef(path, fsr, NULL)) ) {
285288
PyMac_Error(err);
286289
return 0;
287290
}

0 commit comments

Comments
 (0)