]> git.lyx.org Git - features.git/commitdiff
Validate if graphics path is encodable
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 26 Oct 2019 06:33:51 +0000 (08:33 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 31 Oct 2019 09:15:09 +0000 (10:15 +0100)
Fixes #11688

(cherry picked from commit 1c0572f1ab9956cde47fb42ae1a3473ac26964ea)

src/insets/InsetGraphics.cpp
status.23x

index b7b965025b63645e17d1f50595bdfd54ca0915be..fbddab0463a584f207bbd87b72bd6a0f3704b13d 100644 (file)
@@ -54,6 +54,7 @@ TODO
 #include "Converter.h"
 #include "Cursor.h"
 #include "DispatchResult.h"
+#include "Encoding.h"
 #include "ErrorList.h"
 #include "Exporter.h"
 #include "Format.h"
@@ -872,8 +873,43 @@ void InsetGraphics::latex(otexstream & os,
        // Convert the file if necessary.
        // Remove the extension so LaTeX will use whatever is appropriate
        // (when there are several versions in different formats)
-       string file_path = prepareFile(runparams);
-       latex_str += file_path;
+       docstring file_path = from_utf8(prepareFile(runparams));
+       // we can only output characters covered by the current
+       // encoding!
+       docstring uncodable;
+       docstring encodable_file_path;
+       for (size_type i = 0 ; i < file_path.size() ; ++i) {
+               char_type c = file_path[i];
+               try {
+                       if (runparams.encoding->encodable(c))
+                               encodable_file_path += c;
+                       else if (runparams.dryrun) {
+                               encodable_file_path += "<" + _("LyX Warning: ")
+                                               + _("uncodable character") + " '";
+                               encodable_file_path += docstring(1, c);
+                               encodable_file_path += "'>";
+                       } else
+                               uncodable += c;
+               } catch (EncodingException & /* e */) {
+                       if (runparams.dryrun) {
+                               encodable_file_path += "<" + _("LyX Warning: ")
+                                               + _("uncodable character") + " '";
+                               encodable_file_path += docstring(1, c);
+                               encodable_file_path += "'>";
+                       } else
+                               uncodable += c;
+               }
+       }
+       if (!uncodable.empty() && !runparams.silent) {
+               // issue a warning about omitted characters
+               // FIXME: should be passed to the error dialog
+               frontend::Alert::warning(_("Uncodable characters in path"),
+                       bformat(_("The following characters in one of the graphic paths are\n"
+                                 "not representable in the current encoding and have been omitted: %1$s."
+                                 "You need to adapt either the encoding or the path."),
+                       uncodable));
+       }
+       latex_str += to_utf8(encodable_file_path);
        latex_str += '}' + after;
        // FIXME UNICODE
        os << from_utf8(latex_str);
index 93202c5d00e2a160e57e12451b895b87c2967974..8026ad9ae273e64b777b9bda41d2c6f60dbf5c32 100644 (file)
@@ -58,6 +58,8 @@ What's new
 
 * DOCUMENT INPUT/OUTPUT
 
+- Prevent crash due to unencodable path (bug 11688).
+
 - (Re-)fix problems with activated equal sign and graphic options in Turkish
   and Latin documents (bug 2005).