I get errors saying that querystring.filtersep() can’t be used outside of filter_except and filter

I’d like to create a string to pass to the names parameter of querystring.filter_except, so I can conditionally allow some query parameters depending on the route, or whether they match a certain validation. A bit like this:

// declare var.allowed_params 
if (req.url.path ~ "routeA") {
  set var.allowed_params = var.allowed_params + querystring.filtersep() + "paramA";
}

if (querystring.get(req.url, "paramB") ~ "\d+") {
  set var.allowed_params = var.allowed_params + querystring.filtersep() + "paramB";
}
// ...
set req.url = querystring.filter_except(req.url, var.allowed_params);

However, I get errors saying that querystring.filtersep() can’t be used outside of filter_except and filter.

Is there a reason for this restriction? Is there a workaround to help me implement something close to my idea?

Hi George,

I’ve never tried to do this before, but I just gave it a go and you’re correct, using querystring.filtersep() outside of filter_except causes a compiler error. I don’t see any way around that sadly. You’ll need to do that filter_except inside your if statement’s true block.

1 Like