Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percent encode, URLEncodedForm using FoundationEssentials #639

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

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
Copy link

github-actions bot commented Dec 24, 2024

case .formatted(let formatter):
try self.encode(formatter.string(from: date))
#if compiler(>=6.0)
try self.encode(date.formatted(.iso8601))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this affect *OS support from Apple?

charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
)

#if compiler(<6.0)
/// ISO8601 data formatter used throughout URL encoded form code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this affect *OS support from Apple?

@Joannis
Copy link
Member

Joannis commented Dec 26, 2024

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

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.

2 participants