Fix unescape error detection and make it tolerate quotes

parent 60c5271f
......@@ -519,14 +519,12 @@ vmod_unescape(VRT_CTX, VCL_STRING p, VCL_STRING fallback)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (*p != '"' || p[strlen(p) - 1] != '"') {
fail(ctx, fallback, "j.unescape() argument missing quotes");
return (fallback);
}
p++;
if (*p == '"')
p++;
WS_VSB_new(vsb, ctx->ws);
if (vsbjunquot(vsb, p, &err) && err != NULL) {
if (! vsbjunquot(vsb, p, &err) && err != NULL) {
WS_Release(ctx->ws, 0);
fail(ctx, fallback, "j.unescape() error at: ...%.10s", err);
return (fallback);
}
......@@ -540,7 +538,7 @@ vmod_unescape(VRT_CTX, VCL_STRING p, VCL_STRING fallback)
return (r);
l--;
assert(r[l] == '"');
r[l] = '\0';
if (r[l] == '"')
r[l] = '\0';
return (r);
}
......@@ -451,6 +451,9 @@ STRING unescape(STRING, STRING fallback=0)
Utility function to decode JSON strings into UTF-8.
The string may contain surrounding quotes, which are silently removed,
even if only left *or* right quotes are present.
If decoding fails and *fallback* is provided, the error is logged with
tag ``Error`` and *fallback* is returned. Otherwise, the VCL is failed.
......
......@@ -385,6 +385,9 @@ $Function STRING unescape(STRING, STRING fallback=0)
Utility function to decode JSON strings into UTF-8.
The string may contain surrounding quotes, which are silently removed,
even if only left *or* right quotes are present.
If decoding fails and *fallback* is provided, the error is logged with
tag ``Error`` and *fallback* is returned. Otherwise, the VCL is failed.
......
......@@ -110,7 +110,7 @@ varnish v1 -vcl {
set resp.http.o4 = j.object(j.string("A") + j.object(j.nil()));
set resp.http.unok = j.unescape({""abc""});
set resp.http.unno = j.unescape("", j.null());
set resp.http.unno = j.unescape("\udc00", j.null());
set resp.body = "";
return (deliver);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment