sasurajachar / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Unicode control caracters in parameters - java.lang.IllegalArgumentException: Illegal number of path parameters. Expected 1, was 2. #404

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
Parameters in get() method that have unicode control caracters fail with an 
IllegalArgumentException

Example:
                String request = "param1={param1Value}&param2={param2Value}";
        String param1Value =  "Hello";
        String param2Value =  "Hello\u0085";
        System.out.println(param1Value);
        RestAssured.get(request, param1Value, param2Value);

What is the expected output? What do you see instead?
Success of method call get()

What version of the product are you using? On what operating system?
2.4.1

Please provide any additional information below.

The error is in com.jayway.restassured.internal.RequestSpecificationImpl:
     def hasAnyTemplateLeft = ~/.*\{\w+\}.*/

This regex only takes words and not others caracters.

 if (queryParams.matches(pathTemplate)) {
        def hasAnyTemplateLeft = ~/.*\{\w+\}.*/
        def replacePattern = ~/\{\w+\}/
        def definedParams

..... else {
          throw new IllegalArgumentException("Illegal number of path parameters. Expected $numberOfUsedPathParameters, was $expectedNumberOfUsedPathParameters.")
        }
      }

Original issue reported on code.google.com by carlant...@gmail.com on 22 May 2015 at 5:07

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 26 May 2015 at 9:15

GoogleCodeExporter commented 9 years ago
Thanks for reporting. If you would like to help out I would very much 
appreciate a pull request.

Original comment by johan.ha...@gmail.com on 26 May 2015 at 9:15

GoogleCodeExporter commented 9 years ago
I used another library as the performance of rest-assured was 50x to 100x 
slower than regular httpclient and json-simple. 

Original comment by carlant...@gmail.com on 26 May 2015 at 11:41

GoogleCodeExporter commented 9 years ago
Because of this issue?!

Original comment by johan.ha...@gmail.com on 26 May 2015 at 5:47

GoogleCodeExporter commented 9 years ago
Because of this issue I found that rest-assured is super slow for the kind of 
work I do. I execute concurrent tests that run for hours (> 200K requests), 
Rest-assured is very inefficient because of groovy code I suppose.

Original comment by carlant...@gmail.com on 27 May 2015 at 1:34

GoogleCodeExporter commented 9 years ago
I suppose that Groovy could be a reason but I'm sure that I could do things 
internally to optimize it more as well. Would be interesting to know where RA 
spends the most time? It would be great if you could run a profiler on it.

Original comment by johan.ha...@gmail.com on 28 May 2015 at 6:35

GoogleCodeExporter commented 9 years ago
I don't think your issue has anything to do with unicode characters. I think it 
has to do with the fact that your request path is not a valid URI? If I change 
your example to:

String request = "/test?param1={param1Value}¶m2={param2Value}";
String param1Value =  "Hello";
String param2Value =  "Hello\u0085";
System.out.println(param1Value);
RestAssured.get(request, param1Value, param2Value);

then it works!

Original comment by johan.ha...@gmail.com on 6 Jun 2015 at 5:03

GoogleCodeExporter commented 9 years ago
The code (if I remember it correctly) looks for an initial "?" when searching 
for parameters and your request path doesn't include a "?". There should 
probably be a better exception message though.

Original comment by johan.ha...@gmail.com on 6 Jun 2015 at 5:05

GoogleCodeExporter commented 9 years ago
I've fixed a better expection message now

Original comment by johan.ha...@gmail.com on 6 Jun 2015 at 5:14