* @param source The string that was originally matched to the regex
* @param nmatch the nmatch returned from ap_pregex
* @param pmatch the pmatch array returned from ap_pregex
- * @param maxlen the maximum string length to return
+ * @param maxlen the maximum string length to return, 0 for unlimited
* @return The substituted string, or NULL on error
*/
AP_DECLARE(apr_status_t) ap_pregsub_ex(apr_pool_t *p, char **result,
* @param source The string that was originally matched to the regex
* @param nmatch the nmatch returned from ap_pregex
* @param pmatch the pmatch array returned from ap_pregex
- * @param maxlen the maximum string length to append to vb
+ * @param maxlen the maximum string length to append to vb, 0 for unlimited
* @return APR_SUCCESS if successful
* @note Just like ap_pregsub(), this function does not copy the part of
* *source before the matching part (i.e. the first pmatch[0].rm_so
apr_size_t bytes;
apr_size_t len;
const char *buff;
- const char *repl;
struct ap_varbuf vb;
apr_bucket *b;
apr_bucket *tmp_b;
int have_match = 0;
vb.strlen = 0;
if (script->pattern) {
+ const char *repl;
while ((repl = apr_strmatch(script->pattern, buff, bytes)))
{
have_match = 1;
else if (script->regexp) {
int left = bytes;
const char *pos = buff;
+ char *repl;
while (!ap_regexec_len(script->regexp, pos, left,
AP_MAX_REG_MATCH, regm, 0)) {
have_match = 1;
ap_varbuf_strmemcat(&vb, pos, regm[0].rm_so);
/* add replacement string */
ap_varbuf_regsub(&vb, script->replacement, pos,
- AP_MAX_REG_MATCH, regm,
- APR_SIZE_MAX);
+ AP_MAX_REG_MATCH, regm, 0);
}
else {
- repl = ap_pregsub(pool, script->replacement, pos,
- AP_MAX_REG_MATCH, regm);
+ ap_pregsub_ex(pool, &repl, script->replacement, pos,
+ AP_MAX_REG_MATCH, regm, 0);
len = (apr_size_t) (regm[0].rm_eo - regm[0].rm_so);
SEDRMPATBCKT(b, regm[0].rm_so, tmp_b, len);
tmp_b = apr_bucket_transient_create(repl,
return APR_EINVAL;
if (!nmatch || nmatch>AP_MAX_REG_MATCH) {
len = strlen(src);
- if (maxlen > 0 && len > maxlen)
+ if (maxlen > 0 && len >= maxlen)
return APR_ENOMEM;
if (!vb) {
*result = apr_pstrmemdup(p, src, len);
}
- if (len > maxlen && maxlen > 0)
+ if (len >= maxlen && maxlen > 0)
return APR_ENOMEM;
if (!vb) {