Skip to content

Internals

tkb-github edited this page Jun 26, 2024 · 4 revisions

The ‘\\’ problem

A major difference between mod_setenvif and mod_rewrite lies in how they deal with multiple backslashes in regex.

mod_rewrite has its own parser (‘what an inclined parser’!):

    /*
     * determine second argument
     */
    quote = (*str == '"' || *str == '\'') ? *str++ : '\0';
    *a2 = str;

    for (; *str; ++str) {
        if ((apr_isspace(*str) && !quote) || (*str == quote)) {
            break;
        }
        if (*str == '\\' && apr_isspace(str[1])) {
            ++str;
            continue;
        }
    }

mod_setenvif, by contrast, relies on ap_getword_conf, which strips out every other backslash:

    for (i = 0; i < len; ++i) {
        if (start[i] == '\\' && (start[i + 1] == '\\'
                                 || (quote && start[i + 1] == quote)))
            *resp++ = start[++i];
        else
            *resp++ = start[i];
    }

To counter this effect, nG-SetEnvIf uses more backslashes than upstream.

Clone this wiki locally