sahaya / rest-assured

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

urlEncodingEnabled not working as expected #175

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Execute below JUnit test

What is the expected output? What do you see instead?

When urlEncodingEnabled is set to false then restAssured will drop the query 
parameter completely.

What version of the product are you using? On what operating system?
RestAssured: 1.6.1
Java: 1.7
OS: OS X 10.7

Please provide any additional information below.
-> JUnit test class:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.junit.Test;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;

public class DummyTest {

  private static final String HEISE_SEARCH = "http://www.heise.de/suche/?";

  private String search(String query, String... params) {
    String html = RestAssured.given()
        .expect()
            .statusCode(200)
            .contentType(ContentType.HTML)
        .get(HEISE_SEARCH + query, (Object[]) params)
        .asString();

    // find search term in search input element
    Pattern p = Pattern.compile("<input[^>]+search_q[^>]+value=\"([^\"]*)\"");
    Matcher m = p.matcher(html);
    Assert.assertTrue(m.find());

    String echo = m.group(1);
    return echo;
  }

  @Test
  public void testUrlEncoding() {

    Assert.assertEquals("foo", search("q=foo"));
    Assert.assertEquals("%3F", search("q=%3F"));
    Assert.assertEquals("%3F", search("q={token}", "%3F"));

    RestAssured.urlEncodingEnabled = false;

    Assert.assertEquals("foo", search("q=foo"));
    Assert.assertEquals("?", search("q=%3F"));
    Assert.assertEquals("?", search("q={token}", "%3F"));
  }

}

Original issue reported on code.google.com by mi.koel...@googlemail.com on 24 May 2012 at 2:35

GoogleCodeExporter commented 9 years ago
Thanks for the test case

Original comment by johan.ha...@gmail.com on 29 May 2012 at 3:30

GoogleCodeExporter commented 9 years ago
It's fixed in trunk now. Thanks for reporting. I've created an automatic test 
against your service so I hope that it doesn't go down :)

Original comment by johan.ha...@gmail.com on 29 May 2012 at 4:51

GoogleCodeExporter commented 9 years ago
Sad I was on holiday for 3 weeks. I might have been been able to post this 
before 1.6.2 :

The fix falls short. It does not recognize escaped sequences in path segments. 
See below modified test case.

public class DummyTest {

  private static final String APACHE_404 = "http://www.apache.org/question-%3F";

  private String search() {
    String html = RestAssured.given()
        .expect()
            .statusCode(404)
            .contentType(ContentType.HTML)
        .get(APACHE_404)
        .asString();

    // find search term in search input element
    Pattern p = Pattern.compile("/question-(.+?) ");
    Matcher m = p.matcher(html);
    Assert.assertTrue(m.find());

    String echo = m.group(1);
    return echo;
  }

  @Test
  public void testUrlEncoding() {

    Assert.assertEquals("%3F", search());

    RestAssured.urlEncodingEnabled = false;

    Assert.assertEquals("?", search());
  }

}

Original comment by mi.koel...@googlemail.com on 18 Jun 2012 at 11:28

GoogleCodeExporter commented 9 years ago
Thanks for the test case thought I cannot reproduce it with the latest master 
(sha 8a3fc06)

Original comment by johan.ha...@gmail.com on 14 Nov 2013 at 9:58