Changeset 523


Ignore:
Timestamp:
Dec 25, 2007, 2:51:54 AM (13 years ago)
Author:
Peter Johansson
Message:

fixes ticket:284 - validate [file-name-dictionary] section in config file

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Configuration.cc

    r522 r523  
    6666  {
    6767    if (const std::pair<std::string,std::string>* dict=dictionary(file_name))
    68       try {
    69         file_name = translate(file_name, *dict);
    70       }
    71       catch (std::runtime_error& e) {
    72         std::stringstream mess;
    73         mess << "svndigest: invalid config file: "
    74              << "expression " << dict->second << " is invalid";
    75         if (e.what()[0])
    76           mess << "because " << e.what() << " is a too large.";
    77         else
    78           mess << ".";
    79         throw std::runtime_error(mess.str());
    80       }
     68      file_name = translate(file_name, *dict);
    8169    for (String2Codons::const_iterator i(string2codons_.begin());
    8270         i!=string2codons_.end(); ++i) {
     
    125113  {
    126114    set_default();
     115    validate_dictionary();
    127116  }
    128117
     
    268257      }
    269258    }
     259    validate_dictionary();
    270260  }
    271261
     
    300290        size_t n = 0;
    301291        ss >> n;
    302         if (n>vec.size()){
     292        if (n>vec.size() || n==0){
    303293          std::stringstream mess;
    304           mess << n;
    305           throw std::runtime_error(mess.str());
    306         }
    307         if (n) {
    308           res += vec[n-1];
     294          mess << "svndigest: invalid config file: "
     295               << "expression " << dic.second << " is invalid";
     296          if (n)
     297            mess << "because " << n << " is a too large.";
     298          throw std::runtime_error("");       
     299        }
     300        res += vec[n-1];
     301        ++i;
     302        if (n>9){
    309303          ++i;
    310           if (n>9){
     304          if (n>99)
    311305            ++i;
    312             if (n>99)
    313               ++i;
    314           }
    315         }
    316         else
    317           throw std::runtime_error("");
     306
     307        }
    318308      }
    319309      else
     
    412402
    413403
     404  void Configuration::validate_dictionary(void) const
     405  {
     406    VectorPair::const_iterator end(dictionary_.end());
     407    for (VectorPair::const_iterator iter(dictionary_.begin());iter!=end;++iter){
     408      std::string word(iter->first);
     409      replace(word, "*", "");
     410      replace(word, "?", "");
     411      // throws if dictionary is invalid
     412      translate(word, *iter);
     413    }
     414
     415  }
     416
     417
    414418  std::ostream& operator<<(std::ostream& os, const Configuration& conf)
    415419  {
  • trunk/lib/Configuration.h

    r522 r523  
    104104       Translate string \a str using dictionary \a dict
    105105
    106        \note \a str must be equal to d.first, or behavior is unspecified.
     106       \note \a str must be equal to d.first (see function equal),
     107       or behavior is unspecified.
    107108
    108109       \throw if a '$' character is not followed by a positive integer
     
    112113                          const std::pair<std::string, std::string>& d) const;
    113114   
     115    void validate_dictionary(void) const;
     116
    114117    static Configuration* instance_;
    115118
  • trunk/lib/utility.cc

    r519 r523  
    102102        equal(first1+1, end1, first2+1, end2) )
    103103      return true;
    104     if (first1!=end1 && *first1=='*' && first2!=end2 &&
    105         equal(first1, end1, first2+1, end2) )
     104    if ( (first1!=end1 && first2!=end2 && (*first1=='*'|| *first2=='*') ) &&
     105         (equal(first1+1, end1, first2, end2) ||
     106          equal(first1, end1, first2+1, end2))
     107         )
    106108      return true;
    107     if (first2!=end2 && *first2=='*' && first1!=end1 &&
    108         equal(first1+1, end1, first2, end2) )
    109       return true;
    110        
    111109    return false;
    112110  }
  • trunk/test/utility_test.cc

    r519 r523  
    4747  ok &= test_equal(true,"peter", "p*");
    4848  ok &= test_equal(false,"peter", "p*j");
     49  ok &= test_equal(true,"peter", "*peter");
    4950
    5051  std::vector<std::string> vec;
Note: See TracChangeset for help on using the changeset viewer.