9

I have a running app in a webserver, that redirects to an app installed on a iOS 14 device. the url is in the form of

myapp://?p=someBase64EncodedString

and the application is decoding the string. after upgrading to iOS 14, the url the app gets is

myapp://?p=someBase64EncodedString# and the pound symbol added to the end of the string fails to decode on my device. When using ignoreUnknownCharacters everything works fine, but where did this # come from?

Nati
  • 1,034
  • 5
  • 19
  • 46
  • 2
    How is the app decoding the url? A `#` is perfectly valid in a URL and indicates the start of the fragment. See also https://stackoverflow.com/questions/6691495/how-to-load-nsurl-which-contains-hash-fragment-with-uiwebview – jtbandes Nov 12 '20 at 21:29
  • Can you post the full url? (including the `someBase64EncodedString`) – Mojtaba Hosseini Nov 13 '20 at 20:37

3 Answers3

2

As @jtbandes mentioned in the comments, # is valid character in a URL.

To avoid this kind of issues, the safest way to parse a URL is by using URLComponents, following this answer.

Here is an example:

let urlString = "https://test.host.com:8080/Test/Path?test_parameter=test_value#test-fragment"
let urlComponents = URLComponents(string: urlString)

print("scheme: \(urlComponents?.scheme ?? "nil")")
print("host: \(urlComponents?.host ?? "nil")")
print("port: \(urlComponents?.port ?? -1)")
print("path: \(urlComponents?.path ?? "nil")")
print("query: \(urlComponents?.query ?? "nil")")
print("queryItems: \(urlComponents?.queryItems ?? [])")
print("fragment: \(urlComponents?.fragment ?? "nil")")

This will have as output:

scheme: https
host: test.host.com
port: 8080
path: /Test/Path
query: test_parameter=test_value
queryItems: [test_parameter=test_value]
fragment: test-fragment
gcharita
  • 7,729
  • 3
  • 20
  • 37
2

Could Swift 5 and raw strings be the culprit? My guess is that the application is using # as a custom string delimiter and on the decoding is replacing some special character with an #.

Dan M
  • 4,340
  • 8
  • 20
  • I had a similar problem. See here https://www.hackingwithswift.com/articles/126/whats-new-in-swift-5-0 and also https://ericasadun.com/2018/12/26/swift-5-gives-us-nice-things-custom-string-delimiters/ – user308958 Nov 16 '20 at 16:04
0

It may be an api action in a redirect for an api you used. If so, it is out of your control and potentially scope of access.

9pfs
  • 560
  • 5
  • 17