[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-cvs
Subject:    Re: [LyX/master] Handle properly exception that can be thrown by to_local8bit
From:       Enrico Forestieri <forenr () lyx ! org>
Date:       2017-03-28 9:01:35
Message-ID: 20170328090135.GA11196 () GIOVE
[Download RAW message or body]

On Tue, Mar 28, 2017 at 01:43:54AM +0200, Enrico Forestieri wrote:
> On Tue, Mar 28, 2017 at 12:02:02AM +0200, Enrico Forestieri wrote:
> > On Mon, Mar 27, 2017 at 05:05:47PM +0200, Jean-Marc Lasgouttes wrote:
> > > 
> > > Enrico, can you please double check the changes in os_win32.cpp and
> > > os_cygwin.cpp ? I cannot even compile this code.
> > 
> > They are fine and compile Ok. However, that cygwin code is from the
> > time when cygwin was using the same encoding as windows. This is not
> > so anymore since the switch to unicode and utf8. As the path is being
> > passed to a native windows function, it needs proper conversion.
> > I'll have a look. Anyway, this not so harmful as the path refers to
> > a file in the lyx temporary directory, which normally is under /tmp,
> > and lyx mangles the paths so that they are ascii. However, someone
> > could change the temp dir to /tmp/ληχτεμπ, and this would be a problem.
> 
> Yep, that fails. I replaced ShellExecute with ShellExecuteW, and that
> fixed it. However, we have still a problem with native Windows.
> In that scenario (i.e., with unicode chars in the temp dir),
> ofs.open(fname.toFilesystemEncoding().c_str()) in output.cpp fails
> to open the .tex file created in the tempdir. I also tried to replace
> toFilesystemEncoding() with toSafeFilesystemEncoding() but that didn't
> work (at least with the string ληχτεμπ in the path).

Hmm. I must have done something wrong because toSafeFilesystemEncoding()
actually works. The attached patch is required on native windows when
the tempdir path has unicode characters. The change in Buffer.cpp is
required for lyx2lyx.

-- 
Enrico

["tmpdir.diff" (text/plain)]

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index a20b4da..a966f6d 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1313,7 +1313,7 @@ Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn,
 	command << os::python()
 		<< ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
 		<< " -t " << convert<string>(LYX_FORMAT)
-		<< " -o " << quoteName(tmpfile.toFilesystemEncoding())
+		<< " -o " << quoteName(tmpfile.toSafeFilesystemEncoding())
 		<< ' ' << quoteName(fn.toSafeFilesystemEncoding());
 	string const command_str = command.str();
 
diff --git a/src/output.cpp b/src/output.cpp
index 149ba78..7c06473 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -30,7 +30,7 @@ namespace {
 template<typename OFStream>
 bool doOpenFileWrite(OFStream & ofs, FileName const & fname)
 {
-	ofs.open(fname.toFilesystemEncoding().c_str());
+	ofs.open(fname.toSafeFilesystemEncoding().c_str());
 	if (ofs)
 		return true;
 	docstring const file = fname.displayName(50);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic