Cannot escape url as needed

2020-04-28 07:26发布

问题:

I am tring to escape some values in a path.

Let's say I'm trying to obtain https://www.google.com/https%3A%2F%2Fdomain

I've tried the following options :

Scenario: escape value
    * url "https://www.google.com"
    * path "https://domain"
    When method get
    * path "https\:\/\/domain"
    When method get
    * path "https%3A%2F%2Fdomain"
    When method get
    * path "https\\:\\/\\/domain"
    When method get

But I obtain

  1. https://www.google.com/https://domain
  2. https://www.google.com/https://domain
  3. https://www.google.com/https%253A%252F%252Fdomain

Why is \ not working, while %2F is being escaped into %252F?

回答1:

Encoding is the correct behavior: https://www.w3schools.com/tags/ref_urlencode.asp

But your workaround for this un-usual URL is in Karate make it as part of the url itself:

Given url 'https://httpbin.org/https%3A%2F%2Fdomain'
When method get
Then status 200


标签: karate