Ticket #87: omega-terms-with-dots-fix.patch

File omega-terms-with-dots-fix.patch, 2.1 KB (added by Olly Betts, 18 years ago)

Patch

  • query.cc

     
    218218    }
    219219
    220220    // Check new query against the previous one
    221     const char *pend;
    222     const char *term;
    223     unsigned int n_old_terms = 0;
    224 
    225221    if (oldp.empty()) return query_string.empty() ? SAME_QUERY : NEW_QUERY;
    226222
    227223    // We used to use "word1#word2#" (with trailing #) but some broken old
    228224    // browsers (versions of MSIE) don't quote # in form GET submissions
    229225    // and everything after the # gets interpreted as an anchor.
    230     // So now we use "word1.word2." instead.
    231     term = oldp.c_str();
    232     pend = term;
    233     while ((pend = strchr(pend, '.')) != NULL) {
    234         pend++;
    235         n_old_terms++;
     226    //
     227    // So we switched to using "word1.word2." but that doesn't work if
     228    // the terms contain "." themselves (e.g. Tapplication/vnd.ms-excel)
     229    // so now we use "word1\tword2" instead (with no trailing separator).
     230    //
     231    // However for compatibility with templates which haven't been updated and
     232    // bookmarked queries from Omega 0.9.6 and earlier we still support ".".
     233    char separator = '\t';
     234    unsigned int n_old_terms = count(oldp.begin(), oldp.end(), '\t') + 1;
     235    if (n_old_terms == 1 && oldp[oldp.size() - 1] == '.') {
     236        separator = '.';
     237        n_old_terms = count(oldp.begin(), oldp.end(), '.');
    236238    }
     239
    237240    // short-cut: if the new query has fewer terms, it must be a new one
    238241    if (n_new_terms < n_old_terms) return NEW_QUERY;
    239242
    240     while ((pend = strchr(term, '.')) != NULL) {
     243    const char *term = oldp.c_str();
     244    const char *pend;
     245    while ((pend = strchr(term, separator)) != NULL) {
    241246        if (termset.find(string(term, pend - term)) == termset.end())
    242247            return NEW_QUERY;
    243248        term = pend + 1;
    244249    }
     250    if (*term) {
     251        if (termset.find(string(term)) == termset.end())
     252            return NEW_QUERY;
     253    }
     254
    245255    // Use termset.size() rather than n_new_terms so we correctly handle
    246256    // the case when the query has repeated terms.
    247257    // This works wrongly in the case when the user extends the query