Why add double quotation marks for query string which has space characters ?

I used Gatling for performance testing and a problem troubled me a lot recently.
we use “httpReq = httpReq.queryParam(paramName, paramValue)” to build query string. But if there is a space in the “paramValue”, an extra double quotations will be added to query string. This will cause our server cannot extract the key and value correctly.

For example: paramName=“filter”, paramValue=“flag:(A OR B) AND (NOT C)”.
We expected the request sent to server is: http://host:port/questions?filter=flag:(A OR B) AND (NOT C)

But actually, the request we get is http://host:port/questions?“filter=flag:(A OR B) AND (NOT C)” When the server receive this request, it found there are double quotation marks in the query string, so it takes the whole query as a single string, so it cannot to extract the filter and its value, then raise an error message.

How to avoid the double quotation marks to be added in this case? Could anybody help me here? thank you.

Hi,

Could you please explain if the issue is with the code generated by the recorder, or with the way Gatling executes it at runtime.
Could you please provide an actionnable reproducer?
Which version of Gatling do you use?

Hi,

We use gatling-maven-plugin 2.2.4 for testing. And I think the issue is generated when Gatling executes it at runtime. Here is the script we used.

`

class GetRequestSimulator extends Simulation{
private val searchFeeder = csv(inputDataFile).circular
/* Prepare httpConf */
private var httpConf = http
.baseURL(“http://host:port”)
.disableFollowRedirect
.disableWarmUp

/* Prepare http request */
private var httpReq = http(HTTP_REQUEST_NAME)
.get(“search”)

//add query params
if (queryParams != null){

for( param ← queryParams.split("\|") ){
var paramName = if ( param.contains("=") ) param.split("=")(0) else param;
var paramValue = if (param.contains("=") ) param.split("=")(1) else “${”+param+"}"

httpReq = httpReq.queryParam(paramName, paramValue)
}
}

/* Define a scenario */
private val scn = scenario(SCENARIO_NAME)
.feed(searchFeeder)
.exec(httpReq)

/* Form simulation */
setUp(
scn.inject(
constantUsersPerSec(4) during (120)
).protocols(httpConf)
).assertions(global.failedRequests.count.lte(0))
}

`

gatling-maven-plugin 2.2.4

This is not the Gatling version but the gatling-maven-plugin one

Here is the script we used.

Sorry, but this code doesn’t even compile. Please provide a minimal reproducer that we can execute to reproduce your issue.

Thanks

Please try this one
`

package scenarios

import io.gatling.core.Predef.Simulation
import io.gatling.http.Predef.http
import io.gatling.core.Predef.{constantUsersPerSec,global, scenario}
import io.gatling.core.Predef._

class TestRequestSimulator extends Simulation{

  val HTTP_REQUEST_NAME = "TestRequestSimulator"
  val SCENARIO_NAME = "TestRequestSimulator"
  val queryParams = "name=d5d66eddac1|filter=search:(A OR B OR C) AND (NOT test)"

  /* Prepare httpConf */
  private var httpConf = http
    .baseURL("http://localhost")
    .disableFollowRedirect
    .disableWarmUp

  /* Prepare http request */
  private var httpReq = http(HTTP_REQUEST_NAME)
    .get("/search")

  //add query params

  if (queryParams != null){
    println(">>> Add Query Params to Http Request")
    for( param <- queryParams.split("\\|") ){
      var paramName = if ( param.contains("=") ) param.split("=")(0) else param;
      var paramValue = if (param.contains("=") ) param.split("=")(1) else "${"+param+"}"

      httpReq = httpReq.queryParam(paramName, paramValue).ignoreDefaultChecks;
      println(s">>> query param name : ${paramName} , value:  ${paramValue}")
    }
  }

  /* Define a scenario */
  private val scn = scenario(SCENARIO_NAME)
    .exec(httpReq)

  /* Form simulation */
  setUp(
    scn.inject(
      constantUsersPerSec(5) during (10)
    ).protocols(httpConf)
  ).assertions(global.failedRequests.count.lte(0))

}

`
I use this command line to run the script.

mvn gatling:execute -Dgatling.simulationClass=scenarios.TestRequestSimulator

I tried “exec(http(“request”).get(”/").queryParam(“filter”, “search:(A OR B OR C) AND (NOT test)”))"

and got as expected:

GET /?filter=search%3A%28A%20OR%20B%20OR%20C%29%20AND%20%28NOT%20test%29

AFAIK, the issue is most likely on your side.

Thank you.