]> git.lyx.org Git - features.git/commitdiff
Fix bug 2937 (from Jean-Baptiste LAMY)
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 27 Feb 2007 19:01:10 +0000 (19:01 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 27 Feb 2007 19:01:10 +0000 (19:01 +0000)
* src/support/filename.C
(DocFileName::mangledFilenam): Use a whitelist of allowed characters
instead of an incomplete blacklist of disallowed ones

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17378 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/filename.C

index 30ed474054b700583d4fef50791f9b54ead9cee5..abe146ea4d4af999891e4140eda0642fd0bf08fc 100644 (file)
@@ -167,14 +167,19 @@ string const DocFileName::mangledFilename(std::string const & dir) const
        string mname = os::internal_path(name_);
        // Remove the extension.
        mname = changeExtension(name_, string());
-       // Replace '/' in the file name with '_'
-       mname = subst(mname, "/", "_");
-       // Replace '.' in the file name with '_'
-       mname = subst(mname, ".", "_");
-       // Replace ' ' in the file name with '_'
-       mname = subst(mname, " ", "_");
-       // Replace ':' in the file name with '_'
-       mname = subst(mname, ":", "_");
+       // The mangled name must be a valid LaTeX name.
+       // The list of characters to keep is probably over-restrictive,
+       // but it is not really a problem.
+       // Apart from non-ASCII characters, at least the following characters
+       // are forbidden: '/', '.', ' ', and ':'.
+       // On windows it is not possible to create files with '<', '>' or '?'
+       // in the name.
+       static string const keep = "abcdefghijklmnopqrstuvwxyz"
+                                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                                  "+,-0123456789;=";
+       string::size_type pos = 0;
+       while ((pos = mname.find_first_not_of(keep, pos)) != string::npos)
+               mname[pos++] = '_';
        // Add the extension back on
        mname = changeExtension(mname, getExtension(name_));