[master] d5d70a657 varnishncsa: Support balanced pairs of braces within formats

Nils Goroll nils.goroll at uplex.de
Mon Apr 26 09:17:07 UTC 2021


commit d5d70a6578c8645c9bef703340909869dac94c5e
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Apr 26 10:27:23 2021 +0200

    varnishncsa: Support balanced pairs of braces within formats
    
    We now accept braces as long as they come in balanced pairs. As for now,
    might only be useful with %{X}t.
    
    Also extend testing of %{X}t and %{X}T

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 21d95e952..6c5ea6d23 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -631,6 +631,7 @@ parse_format(const char *format)
 	const char *p, *q;
 	struct vsb *vsb;
 	char buf[256];
+	int b;
 
 	if (format == NULL)
 		format = FORMAT;
@@ -712,9 +713,16 @@ parse_format(const char *format)
 		case '{':
 			p++;
 			q = p;
-			while (*q && *q != '}')
+			b = 1;
+			while (*q) {
+				if (*q == '{')
+					b++;
+				else if (*q == '}')
+					if (--b == 0)
+						break;
 				q++;
-			if (!*q)
+			}
+			if (b > 0)
 				VUT_Error(vut, 1, "Unmatched bracket at: %s",
 				    p - 2);
 			assert((unsigned)(q - p) < sizeof buf - 1);
diff --git a/bin/varnishtest/tests/u00003.vtc b/bin/varnishtest/tests/u00003.vtc
index ae81e664c..ee598b1e6 100644
--- a/bin/varnishtest/tests/u00003.vtc
+++ b/bin/varnishtest/tests/u00003.vtc
@@ -149,6 +149,11 @@ req (\d+) rxreq \5 - - - -$} \
 %{VSL:Begin[2]}x %{VSL:Timestamp:Resp}x \
 %{VSL:Timestamp:Resp[2]}x %{VSL:Timestamp:foo}x %{VSL:ReqURL[2]}x"}
 
+# times
+shell -match {^\{\d{4}-\d{2}-\d{2}\}T\{\d{2}:\d{2}:\d{2}\} \{\{\d{4}-\d{2}-\d{2}\T\d{2}:\d{2}:\d{2}\}\} \d+ \d+ \d+} \
+	{varnishncsa -n ${v1_name} -d -F "%{{%F}T{%T}}t %{{{%FT%T}}}t \
+%{s}T %{ms}T %{us}T"}
+
 process p1 -stop -screen-dump
 process p1 -expect-text 1 0 {/1?foo=bar HTTP/1.1" 200 100 "-" "-"}
 process p1 -expect-text 1 0 { - user [}


More information about the varnish-commit mailing list