Skip to content

Commit

Permalink
Fix [43b0656605]: MS Windows: files with emojis are found by glob but…
Browse files Browse the repository at this point in the history
… not recognized by file exists or open
  • Loading branch information
jan.nijtmans committed Sep 13, 2023
2 parents c680b51 + 56f7295 commit 225ba3d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions win/tclWinFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3032,8 +3032,10 @@ TclNativeCreateNativeRep(
WCHAR *nativePathPtr = NULL;
const char *str;
Tcl_Obj *validPathPtr;
size_t len;
int len;
WCHAR *wp;
Tcl_DString ds;
Tcl_Encoding utf8;

if (TclFSCwdIsNative()) {
/*
Expand Down Expand Up @@ -3069,10 +3071,13 @@ TclNativeCreateNativeRep(
Tcl_IncrRefCount(validPathPtr);
}

str = Tcl_GetString(validPathPtr);
len = validPathPtr->length;
utf8 = Tcl_GetEncoding(NULL, "utf-8");
str = Tcl_GetStringFromObj(validPathPtr, &len);
str = Tcl_UtfToExternalDString(utf8, str, len, &ds);
len = Tcl_DStringLength(&ds);
Tcl_FreeEncoding(utf8);

if (strlen(str) != len) {
if (strlen(str) != (size_t)len) {
/*
* String contains NUL-bytes. This is invalid.
*/
Expand Down Expand Up @@ -3166,6 +3171,7 @@ TclNativeCreateNativeRep(
}

done:
Tcl_DStringFree(&ds);
TclDecrRefCount(validPathPtr);
return nativePathPtr;
}
Expand Down

0 comments on commit 225ba3d

Please sign in to comment.