URL Path Bug

Hello, I will start directly with example :

let url1 = URL(string: "https://mywebsite.tech:1234/myservice1.0/myapi/?key1=azwewe&key2=2132")
let url2 = URL(string: "https://mywebsite.tech:1234/myservice1.0/myapi?key1=azwewe&key2=2132")
print("\(url1!.path == url2!.path)")

URL1 & URL2 are different no ?

I'm saying bug cause a GET from /myorders is totally different from /myorders/
or I'm wrong ?

url1 and url2 are different, which is why:

print("\(url1 == url2)")

will print false.

You can tease this out of the URL type with hasDirectoryPath:

print("\(url1!.hasDirectoryPath == url2!.hasDirectoryPath)") // false

This is because the path string for url1 has a trailing forward slash, and so is considered to be a "directory path".

3 Likes

Thank you for the clarification

Terms of Service

Privacy Policy

Cookie Policy