1

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?

Adrien
  • 1,080
  • 4
  • 14

1 Answers1

2

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
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • But the thing is that when trying to encode / (%2F), karate encodes the % to %25. If there is no automatic encoding of /, why is there one for %? Your workaround using url instead of path works, but it complicates things a bit. – Adrien Feb 01 '19 at 10:31
  • @Adrien no it won’t complicate things. you can build a url using string concatenation of a variable if needed. the / is expected in paths. – Peter Thomas Feb 01 '19 at 10:34
  • I know that / is expected in paths, but I don't understand why % isn't, when it is present in encoded parts of the url, and surencoding it isn't really instinctive IMO. – Adrien Feb 01 '19 at 10:49
  • @Adrien ok i don’t know either ;) we just use the apache http client behind. maybe you can submit a pull request ? – Peter Thomas Feb 01 '19 at 10:50
  • 1
    If I manage to do that, I'll for sure contribute to the project :) – Adrien Feb 01 '19 at 10:59