Skip to content

Commit

Permalink
Allow URLs with Unicode Characters (#44)
Browse files Browse the repository at this point in the history
* Adding Support for "Unicode URL" #43 

* Adding support for Swift 5.8
  • Loading branch information
leogdion authored Apr 26, 2023
1 parent 3777765 commit 04117e3
Show file tree
Hide file tree
Showing 11 changed files with 1,246 additions and 18 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/syndikit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
runs-on: [ubuntu-18.04, ubuntu-20.04]
swift-version: [5.5.2, 5.6.2, 5.7]
runs-on: [ubuntu-20.04, ubuntu-22.04]
swift-version: [5.7.3, 5.8]
include:
- runs-on: ubuntu-22.04
swift-version: 5.7.1
- runs-on: ubuntu-20.04
swift-version: 5.5.3
- runs-on: ubuntu-20.04
swift-version: 5.6.3
steps:
- uses: actions/checkout@v3
- name: Cache swift package modules
Expand Down Expand Up @@ -82,21 +84,37 @@ jobs:
iOSVersion: 15.4
watchOSVersion: 8.5
watchName: "Apple Watch Series 7 - 41mm"
iPhoneName: "iPhone 8"
- runs-on: macos-12
xcode: "/Applications/Xcode_13.4.1.app"
iOSVersion: 15.5
watchOSVersion: 8.5
watchName: "Apple Watch Series 7 - 41mm"
iPhoneName: "iPhone 11"
- runs-on: macos-12
xcode: "/Applications/Xcode_14.0.1.app"
iOSVersion: "16.0"
watchOSVersion: "9.0"
watchName: "Apple Watch Series 8 (41mm)"
iPhoneName: "iPhone 12"
- runs-on: macos-12
xcode: "/Applications/Xcode_14.1.app"
iOSVersion: "16.1"
watchOSVersion: "9.1"
watchName: "Apple Watch Ultra (49mm)"
iPhoneName: "iPhone 13"
- runs-on: macos-12
xcode: "/Applications/Xcode_14.2.app"
iOSVersion: "16.2"
watchOSVersion: "9.1"
watchName: "Apple Watch Ultra (49mm)"
iPhoneName: "iPhone 14"
- runs-on: macos-13
xcode: "/Applications/Xcode_14.3.app"
iOSVersion: "16.4"
watchOSVersion: "9.4"
watchName: "Apple Watch Ultra (49mm)"
iPhoneName: "iPhone 14 Pro Max"
steps:
- uses: actions/checkout@v3
- name: Cache swift package modules
Expand Down Expand Up @@ -149,7 +167,7 @@ jobs:
run: rm -rf .build
- name: Lint
run: ./scripts/lint.sh
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' && matrix.xcode == '/Applications/Xcode_14.1.app' }}
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' && matrix.xcode == '/Applications/Xcode_14.3.app' }}
- name: Dump PIF
if: startsWith(matrix.xcode,'/Applications/Xcode_14')
run: |
Expand All @@ -161,15 +179,15 @@ jobs:
ATTEMPT=$(($ATTEMPT+1))
done
- name: Run iOS target tests
run: xcodebuild test -scheme SyndiKit -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13,OS=${{ matrix.iOSVersion }}' -enableCodeCoverage YES build test
run: xcodebuild test -scheme SyndiKit -sdk iphonesimulator -destination 'platform=iOS Simulator,name=${{ matrix.iPhoneName }},OS=${{ matrix.iOSVersion }}' -enableCodeCoverage YES build test
- uses: sersoft-gmbh/swift-coverage-action@v2
- name: Upload iOS coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
flags: iOS,iOS-${{ matrix.iOSVersion }}
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
- name: Run watchOS target tests
run: xcodebuild test -scheme SyndiKit -sdk watchsimulator -destination 'platform=watchOS Simulator,name=${{ matrix.watchName }},OS=${{ matrix.watchOSVersion }}' -enableCodeCoverage YES build test
- uses: sersoft-gmbh/swift-coverage-action@v2
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Created by https://www.toptal.com/developers/gitignore/api/swift,swiftpm,swiftpackagemanager,xcode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=swift,swiftpm,swiftpackagemanager,xcode,macos

Expand Down Expand Up @@ -72,7 +71,7 @@ playground.xcworkspace
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
Packages/
Package.pins
Package.resolved
#Package.resolved
*.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
Expand Down
4 changes: 3 additions & 1 deletion .periphery.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
retain_public: true
targets:
- SyndiKit
1,156 changes: 1,156 additions & 0 deletions Data/XML/news.rss

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Faire/[email protected]
nicklockwood/[email protected]
realm/[email protected]
peripheryapp/periphery@2.10.0
peripheryapp/periphery@2.12.3
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "XMLCoder",
"repositoryURL": "https://github.com/CoreOffice/XMLCoder",
"state": {
"branch": null,
"revision": "666227de3b4cf4adcce7c70b8b89f98c7df02754",
"version": "0.16.0"
}
}
]
},
"version": 1
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/MaxDesiatov/XMLCoder", from: "0.13.1")
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.16.0")
],
targets: [
.target(
Expand Down
5 changes: 1 addition & 4 deletions Scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ if [ "$LINT_MODE" == "NONE" ]; then
elif [ "$LINT_MODE" == "STRICT" ]; then
SWIFTFORMAT_OPTIONS=""
SWIFTLINT_OPTIONS="--strict"
STRINGSLINT_OPTIONS="--config .strict.stringslint.yml"
else
SWIFTFORMAT_OPTIONS=""
SWIFTLINT_OPTIONS=""
STRINGSLINT_OPTIONS="--config .stringslint.yml"
fi

pushd $PACKAGE_DIR
Expand All @@ -40,8 +38,7 @@ if [ -z "$CI" ]; then
$MINT_RUN swiftlint autocorrect
fi

$MINT_RUN periphery scan
$MINT_RUN stringslint lint $STRINGSLINT_OPTIONS
$MINT_RUN periphery scan
$MINT_RUN swiftformat --lint $SWIFTFORMAT_OPTIONS .
$MINT_RUN swiftlint lint $SWIFTLINT_OPTIONS

Expand Down
35 changes: 35 additions & 0 deletions Sources/SyndiKit/Common/Primitives/UTF8EncodedURL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation

internal struct UTF8EncodedURL: Codable {
internal let value: URL
internal let string: String?

internal init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
do {
value = try container.decode(URL.self)
string = nil
} catch let error as DecodingError {
let string = try container.decode(String.self)

let encodedURLString = string.addingPercentEncoding(
withAllowedCharacters: .urlQueryAllowed
)
let encodedURL = encodedURLString.flatMap(URL.init(string:))
guard let encodedURL = encodedURL else {
throw error
}
value = encodedURL
self.string = string
}
}

internal func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
if let string = string {
try container.encode(string)
} else {
try container.encode(value)
}
}
}
6 changes: 6 additions & 0 deletions Sources/SyndiKit/Formats/Feeds/Atom/AtomMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ public struct AtomMedia: Codable {

/// The direct URL to the media object.
public let medium: String?

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
url = try container.decode(UTF8EncodedURL.self, forKey: .url).value
medium = try container.decodeIfPresent(String.self, forKey: .medium)
}
}
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct Enclosure: Codable {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Self.CodingKeys)
url = try container.decode(URL.self, forKey: .url)
url = try container.decode(UTF8EncodedURL.self, forKey: .url).value
type = try container.decode(String.self, forKey: .type)
if container.contains(.length) {
do {
Expand Down

0 comments on commit 04117e3

Please sign in to comment.