Does Play provide any guarantees for the order of the query string values?

I am adding a generic extension to my Scala 2.11.6, Play 2.3.8 project based on Request.queryString

/**
 * The parsed query string.
 */
def queryString: Map[String, Seq[String]]

      

Let's say I have ?param=A&param=B

. The order in which the query returns A and B affects the calculation result.

Does procedure A and B comply with warranty?

In other words, I need to explicitly handle the order of the request parameters or part of the system contract.

+3


source to share


1 answer


Does guarantee order A and B follow?

I don't think there is an explicit guarantee regarding the order of the parameters in Play (in general).

In the version I'm using now (Play 2.3.8), Play seems to use the Netty QueryStringDecoder and does preserve the order of the value.

So with something like /some/path?param=1&param=7&param=4

, queryString()

will return



"param" -> ["1", "7", "4"]

      

but no one can assure you that this will not change in the future (either Netty or Play decides to use something else).

If you're really just targeting 2.3.8, I think you can safely assume the order is saved. If you want to use other versions of Play, you can explicitly use the version Netty QueryStringDecoder

used in 2.3.8:

QueryStringDecoder qs = new QueryStringDecoder("/a?param=1&param=7&param=4");
Map<String, List<String>> queryString = qs.getParameters(); 

      

+3


source







All Articles