]> git.lyx.org Git - features.git/commitdiff
Fix Bug 3947: BibTeX allows parentheses in the key (even if the whole entry is delimi...
authorBernhard Roider <bernhard.roider@sonnenkinder.org>
Mon, 2 Jul 2007 18:01:27 +0000 (18:01 +0000)
committerBernhard Roider <bernhard.roider@sonnenkinder.org>
Mon, 2 Jul 2007 18:01:27 +0000 (18:01 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18966 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetBibtex.cpp

index 6870b58134efb612a94c461e41000ef26b62837c..bb8cd53987ccd6e548db252b4b68e2780c8e8536 100644 (file)
@@ -393,7 +393,8 @@ namespace {
        /// @return true if a string of length > 0 could be read.
        ///
        bool readTypeOrKey(docstring & val, idocfstream & ifs,
-               docstring const & delimChars, charCase chCase) {
+               docstring const & delimChars, docstring const &illegalChars, 
+               charCase chCase) {
 
                char_type ch;
 
@@ -411,7 +412,11 @@ namespace {
                        return false;
 
                // read value
-               while (ifs && !isSpace(ch) && delimChars.find(ch) == docstring::npos) {
+               bool legalChar;
+               while (ifs && !isSpace(ch) && 
+                          delimChars.find(ch) == docstring::npos &&
+                          (legalChar = illegalChars.find(ch) == docstring::npos)
+                          ) {
                        if (chCase == makeLowerCase) {
                                val += lowercase(ch);
                        } else {
@@ -419,6 +424,11 @@ namespace {
                        }
                        ifs.get(ch);
                }
+               
+               if (!legalChar) {
+                       ifs.putback(ch);
+                       return false;
+               }
 
                // skip whitespace
                while (ifs && isSpace(ch)) {
@@ -596,7 +606,8 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
 
                        docstring entryType;
 
-                       if (!readTypeOrKey(entryType, ifs, from_ascii("{("), makeLowerCase) || !ifs)
+                       if (!readTypeOrKey(entryType, ifs, from_ascii("{("), 
+                                          docstring(), makeLowerCase) || !ifs)
                                continue;
 
                        if (entryType == from_ascii("comment")) {
@@ -623,9 +634,11 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
                                docstring name;
                                docstring value;
 
-                               if (!readTypeOrKey(name, ifs, from_ascii("#=}),"), makeLowerCase) || !ifs)
+                               if (!readTypeOrKey(name, ifs, from_ascii("="), 
+                                                  from_ascii("#{}(),"), makeLowerCase) || !ifs)
                                        continue;
 
+                               // next char must be an equal sign
                                ifs.get(ch);
                                if (!ifs || ch != '=')
                                        continue;
@@ -653,7 +666,8 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
                                docstring value;
                                docstring commaNewline;
 
-                               if (!readTypeOrKey(key, ifs, from_ascii(",})"), keepCase) || !ifs)
+                               if (!readTypeOrKey(key, ifs, from_ascii(","), 
+                                                  from_ascii("}"), keepCase) || !ifs)
                                        continue;
 
                                // now we have a key, so we will add an entry
@@ -667,7 +681,8 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
                                while (ifs && readNext) {
 
                                        // read field name
-                                       if (!readTypeOrKey(name, ifs, from_ascii("=}),"), makeLowerCase) || !ifs)
+                                       if (!readTypeOrKey(name, ifs, from_ascii("="), 
+                                                          from_ascii("{}(),"), makeLowerCase) || !ifs)
                                                break;
 
                                        // next char must be an equal sign