]> git.lyx.org Git - features.git/commitdiff
Prevent crash in the file browser if the file mask is an invalid regex.
authorAngus Leeming <leeming@lyx.org>
Fri, 2 Jan 2004 21:54:09 +0000 (21:54 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 2 Jan 2004 21:54:09 +0000 (21:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8293 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/FileDialog.C
src/frontends/xforms/FormFiledialog.C

index dd2fbaba5531ed1d412d502d6b8decc7e1c2f9fb..8ee362c97ad064f19696d2f5c06fe9a0b3862058 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-02  Angus Leeming  <leeming@lyx.org>
+
+       * FormFiledialog.C (globMatch): prevent crash when using an invalid
+       glob.
+       (getRegex): renamed as glob2regex.
+
+       * FileDialog.C (open): remove the block of old code that splits the
+       filter into a description and a glob using '|' as the delimiter.
+
 2003-12-28  Angus Leeming  <leeming@lyx.org>
 
        * xforms_helpers.C (read, write): output a diagnostic message if
index 8582cd32026aa60729a2b379ad078b93913f6b28..9a2ba425c953354f66f7875f56b1ae0921d5dd70 100644 (file)
@@ -65,14 +65,8 @@ FileDialog::Result const FileDialog::opendir(string const & path, string const &
 FileDialog::Result const FileDialog::open(string const & path, string const & mask, string const & suggested)
 {
        string filter = mask;
-
-       if (mask.empty())
-               filter = _("*");
-       else {
-               rsplit(mask, filter, '|');
-               if (filter.empty())
-                       filter = mask;
-       }
+       if (filter.empty())
+               filter = "*";
 
        lyxerr[Debug::GUI] << "filedialog open  with path \"" << path << "\", mask \""
                << filter << "\", suggested \"" << suggested << '"' << endl;
index 3d9d5b05c4c0d608a058e826fb99f0790237c248..3dd5faec70aee2af97119932ae77791ca3185f01 100644 (file)
@@ -200,7 +200,7 @@ int FileDialog::Private::minh_ = 0;
 
 namespace {
 
-boost::regex getRegex(string const & pat)
+boost::regex glob2regex(string const & pat)
 {
        // We massage the pattern a bit so that the usual
        // shell pattern we all are used to will work.
@@ -217,7 +217,8 @@ boost::regex getRegex(string const & pat)
 
 bool globMatch(string const & a, boost::regex const & reg)
 {
-       return boost::regex_match(a, reg);
+       // If the glob is invalid then match everything.
+       return reg.empty() ? true : boost::regex_match(a, reg);
 }
 
 } // namespace anon
@@ -251,9 +252,9 @@ void FileDialog::Private::Reread()
        string line, Temp;
        string mode;
        string File = directory_;
-       if (File != "/") {
+       if (File != "/")
                File = split(File, Temp, '/');
-       }
+
        while (!File.empty() || !Temp.empty()) {
                string dline = "@b" + line + Temp + '/';
                fl_add_browser_line(file_dlg_form_->List, dline.c_str());
@@ -263,7 +264,7 @@ void FileDialog::Private::Reread()
        }
 
        // Parses all entries of the given subdirectory
-       boost::regex reg = getRegex(mask_);
+       boost::regex const mask_regex = glob2regex(mask_);
 
        time_t curTime = time(0);
        rewinddir(dir);
@@ -348,7 +349,7 @@ void FileDialog::Private::Reread()
                    || fileInfo.isChar()
                    || fileInfo.isBlock()
                    || fileInfo.isFifo()) {
-                       if (!globMatch(fname, reg))
+                       if (!globMatch(fname, mask_regex))
                                continue;
                } else if (!(isDir = fileInfo.isDir()))
                        continue;
@@ -417,7 +418,10 @@ void FileDialog::Private::SetDirectory(string const & path)
 // SetMask: sets dialog file mask
 void FileDialog::Private::SetMask(string const & newmask)
 {
-       mask_ = newmask;
+       mask_ = trim(newmask);
+       if (mask_.empty())
+               mask_ = "*";
+
        fl_set_input(file_dlg_form_->PatBox, mask_.c_str());
 }
 
@@ -433,7 +437,7 @@ void FileDialog::Private::SetInfoLine(string const & line)
 FileDialog::Private::Private()
 {
        directory_ = MakeAbsPath(string("."));
-       mask_ = '*';
+       mask_ = "*";
 
        // Creates form if necessary.
        if (!file_dlg_form_) {