Skip to content

Bridging is not identical from NSURLComponents to URLComponents #828

Closed
@giginet

Description

@giginet

Description

A bridging behavior from NSURLComponents to URLComponents is strange. If the string contains URL encoded strings, bridging from ObjC implementation to Swift struct seems not to be identical.

This behavior seems to work fine below iOS 17 correctly, but on iOS 18, the following tests are broken. I guess, since the iOS 18 family, the Implementation of URLComponents in Foundation was replaced by this product.

Sample Code

Create an empty package and run the following test on each simulator.

They will be passed with iOS 17 simulators, but the conversion from ObjC to Swift would break with iOS 18 simulators

import Testing

@Suite
struct URLComponentConversion {
    @Test func bridgingToSwift() {
        let nsURLComponents = NSURLComponents(
            string: "https://example.com?url=https%3A%2F%2Fapple.com"
        )!
        let urlComponents = nsURLComponents as URLComponents
        // This will be failure only on iOS 18
        #expect(urlComponents.string == nsURLComponents.string)
    }

    @Test func bridgingToObjC() {
        let urlComponents = URLComponents(
            string: "https://example.com?url=https%3A%2F%2Fapple.com"
        )!
        let nsURLComponents = urlComponents as NSURLComponents
        #expect(urlComponents.string == nsURLComponents.string)
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions