Skip to content

Url encoding/decoding deprecation warning for unsupported encoding #44

@alexander-albers

Description

@alexander-albers

Some providers require url encoding or decoding using non-utf8 charsets. This behavior has been deprecated by Apple for some years now.

extension String {
public func decodeUrl(using encoding: String.Encoding) -> String? {
return (self as NSString).replacingPercentEscapes(using: encoding.rawValue)
}
public func encodeUrl(using encoding: String.Encoding) -> String? {
return (self as NSString).addingPercentEscapes(using: encoding.rawValue)
}
}

Those methods already have been removed from the Swift String class and are only available for NSString:
https://github.com/apple/swift-corelibs-foundation/blob/eec4b26deee34edb7664ddd9c1222492a399d122/Sources/Foundation/NSStringAPI.swift#L2165

Deprecation warning for NSString: Use -stringByRemovingPercentEncoding instead, which always uses the recommended UTF-8 encoding.

decodeUrl

  • used by Hafas Legacy with isoLatin1 encoding

encodeUrl

  • used by UrlBuilder
  • VBB, Linz and NVBW use isoLatin1 encoding

Currently, everything still works fine, but this url encoding/decoding may need to be reimplemented at some point in the future if Apple decides to completely remove the respective methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions