无法根据需要转义网址

时间:2019-02-01 09:18:48

标签: karate

我想逃避路径中的某些值。

假设我正在尝试获取https://www.google.com/https%3A%2F%2Fdomain

我尝试了以下选项:

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

但是我得到

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

\被转义为%2F时,为什么%252F不起作用?

1 个答案:

答案 0 :(得分:2)

编码是正确的行为:https://www.w3schools.com/tags/ref_urlencode.asp

但是,您可以在Karate中使用此异常URL来解决此问题,使其成为url本身的一部分:

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