[master] 11b8a7ebd Reinstitute multi-line VSL queries

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Jun 12 04:58:12 UTC 2019


commit 11b8a7ebdb30516b4181c8ae61e9b0ce150f08de
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Jun 5 14:12:39 2019 +0200

    Reinstitute multi-line VSL queries
    
    Forcing one line per query can lead to very long lines for cases where
    we can't decompose OR-able individual queries. Where newline previously
    acted as a mere space between tokens, the backslash-newline sequence now
    fills that void.

diff --git a/bin/varnishtest/tests/u00014.vtc b/bin/varnishtest/tests/u00014.vtc
index 9667d85c6..488357e1b 100644
--- a/bin/varnishtest/tests/u00014.vtc
+++ b/bin/varnishtest/tests/u00014.vtc
@@ -54,7 +54,8 @@ shell -err -expect "Query expression error" {
 
 shell -err -expect "Query expression error" {
 	varnishncsa -d -n ${v1_name} -q '
-		* ~ "Incomplete quoted string
+		* ~ "Incomplete quoted
+		string"
 	'
 }
 
@@ -137,7 +138,32 @@ shell -match "^500 503 $" {
 	./ncsa.sh -Q query1.vslq -q 'RespStatus == 503'
 }
 
-# Make v1 log a multiline VSL record and query it
+shell -match "^500 $" {
+	set -e
+
+	tee query1_cont.vslq <<-EOF | wc -l | grep -q 4 # ensure 4 lines
+	# line continuation
+	RespStatus \\
+	== \\
+	500
+	EOF
+
+	./ncsa.sh -Q query1_cont.vslq
+}
+
+shell -err -expect "Query expression error" {
+	set -e
+
+	tee string_cont.vslq <<-EOF | wc -l | grep -q 3 # ensure 3 lines
+	# quoted string continuation
+	* ~ "very long \\
+	string"
+	EOF
+
+	varnishncsa -d -n ${v1_name} -Q string_cont.vslq
+}
+
+# Make v1 log a multiline VSL record and query it (hardly useful)
 
 logexpect l1 -v v1 -g raw -q {CLI ~ "\\nvcl1.s1"} {
 	expect 0 0 CLI "vcl1.s1 +healthy"
diff --git a/doc/sphinx/reference/vsl-query.rst b/doc/sphinx/reference/vsl-query.rst
index 072747f4c..71534a4b0 100644
--- a/doc/sphinx/reference/vsl-query.rst
+++ b/doc/sphinx/reference/vsl-query.rst
@@ -151,6 +151,23 @@ is identical to this query::
 Comments can be used and will be ignored, they start with the ``'#'``
 character, which may be more useful when the query is read from a file.
 
+For very long queries that couldn't easily be split into multiple queries
+it is possible to break them into multiple lines with a backslash preceding
+an end of line.
+
+For example this query::
+
+  BerespStatus >= 500
+
+is identical to this query::
+
+  BerespStatus \
+  >= \
+  500
+
+A backslash-newline sequence doesn't continue a comment on the next line
+and isn't allowed in a quoted string.
+
 Record selection criteria
 -------------------------
 
diff --git a/lib/libvarnishapi/vxp_lexer.c b/lib/libvarnishapi/vxp_lexer.c
index 57f0c971f..b1e952a12 100644
--- a/lib/libvarnishapi/vxp_lexer.c
+++ b/lib/libvarnishapi/vxp_lexer.c
@@ -106,6 +106,11 @@ vxp_Lexer(struct vxp *vxp)
 			continue;
 		}
 
+		if (*p == '\\' && p[1] == '\n') {
+			p += 2;
+			continue;
+		}
+
 		/* Skip comments */
 		if (*p == '#') {
 			while (p < vxp->e && *p != '\n')
@@ -128,7 +133,7 @@ vxp_Lexer(struct vxp *vxp)
 			for (q = p + 1; q < vxp->e; q++) {
 				if (*q == '\\') {
 					q++;
-					if (q == vxp->e)
+					if (q == vxp->e || *q == '\n')
 						break;
 				} else if (*q == '\n') {
 					break;


More information about the varnish-commit mailing list