Skip to content

Commit

Permalink
convert utf-8 encoded path name to escaped unicode when saving docume…
Browse files Browse the repository at this point in the history
…nt with Python
  • Loading branch information
wwmayer committed Sep 12, 2016
1 parent a12ecd4 commit 05a2596
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/App/DocumentPyImp.cpp
Expand Up @@ -83,11 +83,14 @@ PyObject* DocumentPy::save(PyObject * args)
PyObject* DocumentPy::saveAs(PyObject * args)
{
char* fn;
if (!PyArg_ParseTuple(args, "s", &fn)) // convert args: Python->C
return NULL; // NULL triggers exception
if (!PyArg_ParseTuple(args, "et", "utf-8", &fn))
return NULL;

std::string utf8Name = fn;
PyMem_Free(fn);

try {
if (!getDocumentPtr()->saveAs(fn)) {
if (!getDocumentPtr()->saveAs(utf8Name.c_str())) {
PyErr_SetString(PyExc_ValueError, "Object attribute 'FileName' is not set");
return NULL;
}
Expand All @@ -101,9 +104,9 @@ PyObject* DocumentPy::saveAs(PyObject * args)
return 0;
}

Base::FileInfo fi(fn);
Base::FileInfo fi(utf8Name);
if (!fi.isReadable()) {
PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", fn);
PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", utf8Name.c_str());
return NULL;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gui/Document.cpp
Expand Up @@ -43,6 +43,7 @@
#include <Base/Matrix.h>
#include <Base/Reader.h>
#include <Base/Writer.h>
#include <Base/Tools.h>

#include <App/Document.h>
#include <App/DocumentObject.h>
Expand Down Expand Up @@ -670,8 +671,9 @@ bool Document::saveAs(void)
// save as new file name
try {
Gui::WaitCursor wc;
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs(\"%s\")"
, DocName, (const char*)fn.toUtf8());
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(fn.toUtf8());
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs(u\"%s\")"
, DocName, escapedstr.c_str());
setModified(false);
getMainWindow()->appendRecentFile(fi.filePath());
}
Expand Down

0 comments on commit 05a2596

Please sign in to comment.