Skip to content

Comments

Percent encode, URLEncodedForm using FoundationEssentials#639

Merged
adam-fowler merged 10 commits intomainfrom
percent-encode
Jan 13, 2025
Merged

Percent encode, URLEncodedForm using FoundationEssentials#639
adam-fowler merged 10 commits intomainfrom
percent-encode

Conversation

@adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Dec 24, 2024

  • Replace percentDecode function with internal one removingURLPercentEncoding from FoundationEssentials
  • Add addingPercentEncoding
  • Use in URLEncodedForm code
  • Replace ISO8601 date formatter with 6.0 Date format parser and style if available

And...

  • Breaking change: remove URLEncodedFormDecoder.DateDecodingStrategy.formatted and equivalent URLEncodedFormEncoder version. This uses DateFormatter a pre swift 6.0 type. We cannot remove our dependency on Foundation without removing this. In theory we could add a HummingbirdFoundationCompat to include this in as it can be implemented with .custom in a similar way to how JSONEncoder does it.
    public static func formatted(_ formatter: DateFormatter) -> Self {
        .custom { decoder in
            let container = try decoder.singleValueContainer()
            let result = try container.decode(String.self)
            if let date = formatter.date(from: result) {
                return date
            } else {
                throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Date string does not match format expected by formatter."))
            }
        }
    }

@adam-fowler adam-fowler requested a review from Joannis as a code owner December 24, 2024 11:40
@github-actions
Copy link

github-actions bot commented Dec 24, 2024

@Joannis
Copy link
Member

Joannis commented Dec 26, 2024

Assuming this doesn't break older Apple OS'es, LGTM

@adam-fowler adam-fowler added the breaking change Change that requires a major version label Dec 28, 2024
@adam-fowler
Copy link
Member Author

I've removed the breaking change, because I think it needs more discussion

@adam-fowler adam-fowler removed the breaking change Change that requires a major version label Jan 13, 2025
@adam-fowler adam-fowler merged commit f7a769b into main Jan 13, 2025
7 checks passed
@adam-fowler adam-fowler deleted the percent-encode branch January 13, 2025 10:48
@Cyberbeni
Copy link
Contributor

@adam-fowler I think the breaking change issue could be resolved by introducing a new conditional compilation flag. So if people depend on this package and use swift build -Xswiftc -DFOUNDATION_ESSENTIALS_ONLY then they would build the version that only depends on FoundationEssentials but people who don't add this flag will continue to have the old API. Of course it would be nice for such a compilation flag to be unified across the whole swift-server ecosystem.

@adam-fowler
Copy link
Member Author

@adam-fowler I think the breaking change issue could be resolved by introducing a new conditional compilation flag. So if people depend on this package and use swift build -Xswiftc -DFOUNDATION_ESSENTIALS_ONLY then they would build the version that only depends on FoundationEssentials but people who don't add this flag will continue to have the old API. Of course it would be nice for such a compilation flag to be unified across the whole swift-server ecosystem.

We have discussed used the SwiftPM traits support coming in Swift 6.1 for these kind of things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants