Why is an empty req.url.qs "truthy"?

Comments

1 comment

  • Squee

    Hey Victor,

    Excellent question. 

    req.url.qs evaluates to true because the variable will always exist, it's just that sometimes it's empty. I think if you change your conditional to check if the query string is empty, this operator will behave the way you want:

    set req.url = req.url.path + "/" + if(req.url.qs != "", "?" + req.url.qs, "");

    If you'd like to try that out further, here's a fiddle I made that set that up for your testing. Feel free to clone the fiddle to make any changes you want to test out.

    Please let me know if you have any follow up questions or concerns. If you have a specific programmatic need, always feel free to open up a ticket with support at support@fastly.com. We love digging into these kinds of questions!

    Thank you,

    Squee

Please sign in to leave a comment.