]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: sample: Make the `word` converter compatible with `-m found`
authorTim Duesterhus <tim@bastelstu.be>
Thu, 30 Nov 2023 15:41:17 +0000 (16:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Dec 2023 13:35:47 +0000 (14:35 +0100)
Previously an expression like:

    path,word(2,/) -m found

always returned `true`.

Bug exists since the `word` converter exists. That is:
c9a0f6d0232cf44d6b08d1964b9097a45a6c65f0

The same bug was previously fixed for the `field` converter in commit
4381d26edc03faa46401eb0fe82fd7be84be14fd.

The fix should be backported to 1.6+.

reg-tests/converter/word.vtc [new file with mode: 0644]
src/sample.c

diff --git a/reg-tests/converter/word.vtc b/reg-tests/converter/word.vtc
new file mode 100644 (file)
index 0000000..acd4678
--- /dev/null
@@ -0,0 +1,43 @@
+varnishtest "word converter Test"
+
+feature ignore_unknown_macro
+
+server s1 {
+       rxreq
+       txresp -hdr "Connection: close"
+} -repeat 3 -start
+
+haproxy h1 -conf {
+    defaults
+       mode http
+       timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+       timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
+       timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"
+
+    frontend fe
+       bind "fd@${fe}"
+
+       #### requests
+       http-request set-var(txn.uri) path
+       http-response set-header Found %[var(txn.uri),word(2,/)] if { var(txn.uri),word(2,/) -m found }
+
+       default_backend be
+
+    backend be
+       server s1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe_sock} {
+       txreq -url "/foo/bar/baz"
+       rxresp
+       expect resp.status == 200
+       expect resp.http.found == "bar"
+       txreq -url "/foo//bar/baz"
+       rxresp
+       expect resp.status == 200
+       expect resp.http.found == "bar"
+       txreq -url "/foo"
+       rxresp
+       expect resp.status == 200
+       expect resp.http.found == "<undef>"
+} -run
index c8954ac47692b81546d9453433c99ef44b530956..29967e07d99b7f6e00d024a432500731e169fd1b 100644 (file)
@@ -2964,7 +2964,7 @@ static int sample_conv_word(const struct arg *arg_p, struct sample *smp, void *p
        /* Field not found */
        if (word != arg_p[0].data.sint) {
                smp->data.u.str.data = 0;
-               return 1;
+               return 0;
        }
 found:
        smp->data.u.str.data = end - start;