From aeeed9be5cc51ff81364c3c02291325114ae4019 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 13:07:16 +0000 Subject: [PATCH 1/5] Update to Swift tools 5.9 and GitHub Actions CI - swift-tools-version 5.9 with minimum platforms, test target depends on the library - Replace Travis, Hound and Codecov config with a GitHub Actions workflow on macOS and Linux - Keep rejecting invalid URL strings on macOS 14+/iOS 17+, where URL(string:) now percent-encodes them - Make DecodingError Sendable Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01237XKu4FYZRdEg2D5963qC --- .github/workflows/ci.yml | 28 ++++++++++++++++ .hound.yml | 2 -- .swift-version | 1 - .travis.yml | 33 ------------------- CHANGELOG.md | 7 ++++ Package.swift | 13 +++++--- README.md | 7 ++-- Sources/JSONUtilities/DecodingError.swift | 3 ++ .../URL+JSONPrimitiveConvertible.swift | 7 ++++ codecov.yml | 9 ----- 10 files changed, 57 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .hound.yml delete mode 100644 .swift-version delete mode 100644 .travis.yml delete mode 100644 codecov.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9164217 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI +on: + push: + branches: [master] + pull_request: {} +jobs: + macos: + runs-on: macos-15 + name: macOS + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build + - name: Test + run: swift test + linux: + runs-on: ubuntu-latest + name: Linux (Swift ${{ matrix.swift }}) + strategy: + matrix: + swift: ["5.10", "6.1"] + container: swift:${{ matrix.swift }} + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build + - name: Test + run: swift test diff --git a/.hound.yml b/.hound.yml deleted file mode 100644 index c2b241e..0000000 --- a/.hound.yml +++ /dev/null @@ -1,2 +0,0 @@ -swift: - config_file: .swiftlint.yml \ No newline at end of file diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 35a06be..0000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -3.0-GM-CANDIDATE \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 47ceb89..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -os: - - osx -language: generic -osx_image: xcode8 - -env: - - PLATFORM=Mac - - PLATFORM=iOS NAME='iPhone 6s' - - PLATFORM=tvOS NAME='Apple TV 1080p' - - PLATFORM=watchOS - - PLATFORM=SPM - -before_install: - - if [ -n "$NAME" ]; then - export UUID=$(instruments -s | ruby -e "ARGF.each_line{ |ln| ln =~ /$NAME .* \[(.*)\]/; if \$1; puts(\$1); exit; end }"); - fi - -script: - - set -o pipefail; - case $PLATFORM in - Mac) - xcodebuild -scheme JSONUtilities -enableCodeCoverage YES test | xcpretty;; - iOS|tvOS) - open -a "simulator" --args -CurrentDeviceUDID "$UUID" && xcodebuild -scheme JSONUtilities -destination "id=$UUID" -enableCodeCoverage YES test | xcpretty;; - watchOS) - xcodebuild -scheme JSONUtilities -destination "name=Apple Watch - 38mm" | xcpretty;; - SPM) - swift build && swift test;; - esac - -after_success: - - sleep 5 - - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64b70e3..c61ec39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## Next Version + +- Updated to Swift tools version 5.9, with minimum platforms of macOS 10.15, iOS 13, tvOS 13 and watchOS 6 +- `URL` decoding rejects invalid URL strings again on macOS 14, iOS 17 and later, where `URL(string:)` started percent-encoding them +- `DecodingError` is now `Sendable` +- Replaced Travis CI with GitHub Actions on macOS and Linux + ## 4.0.0 - Decoded typed dictionaries now filter out invalid objects by default instead of failing the whole response. This aligns with the defaults of how arrays are decoded. diff --git a/Package.swift b/Package.swift index 73758e8..0204978 100644 --- a/Package.swift +++ b/Package.swift @@ -1,15 +1,20 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.9 import PackageDescription let package = Package( name: "JSONUtilities", + platforms: [ + .macOS(.v10_15), + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + ], products: [ - .library(name: "JSONUtilities", targets: ["JSONUtilities"]) + .library(name: "JSONUtilities", targets: ["JSONUtilities"]), ], - dependencies: [], targets: [ .target(name: "JSONUtilities"), - .testTarget(name: "JSONUtilitiesTests") + .testTarget(name: "JSONUtilitiesTests", dependencies: ["JSONUtilities"]), ] ) diff --git a/README.md b/README.md index b7ff676..e5b7b60 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # JSONUtilities -[![Build Status](https://travis-ci.org/lucianomarisi/JSONUtilities.svg?branch=master)](https://travis-ci.org/lucianomarisi/JSONUtilities) +[![CI](https://github.com/yonaskolb/JSONUtilities/actions/workflows/ci.yml/badge.svg)](https://github.com/yonaskolb/JSONUtilities/actions/workflows/ci.yml) [![](https://img.shields.io/cocoapods/v/JSONUtilities.svg)](https://cocoapods.org/pods/JSONUtilities) [![](https://img.shields.io/cocoapods/p/JSONUtilities.svg)](https://cocoapods.org/pods/JSONUtilities) -[![codecov.io](http://codecov.io/github/lucianomarisi/JSONUtilities/coverage.svg?branch=master)](http://codecov.io/github/lucianomarisi/JSONUtilities?branch=master) ![Carthage Compatible](https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat) -![Swift Version](https://img.shields.io/badge/swift-3.0-brightgreen.svg) +![Swift Version](https://img.shields.io/badge/swift-5.9-brightgreen.svg) Easily load JSON objects and decode them into structs or classes. The `json(atKeyPath:)` function infers the type from the constant or variable definition to decode meaning no casting is needed. Both string keys and keypaths (keys separated by dots `.`) are supported when decoding JSON. @@ -27,7 +26,7 @@ Add the files inside the `Sources` folder into your Xcode project. **Swift Package Manager:** -Add the line `.Package(url: "https://github.com/lucianomarisi/JSONUtilities", majorVersion: 3)` to your `Package.swift`. +Add the line `.package(url: "https://github.com/yonaskolb/JSONUtilities.git", from: "4.2.0")` to the dependencies in your `Package.swift`. ## Types supported diff --git a/Sources/JSONUtilities/DecodingError.swift b/Sources/JSONUtilities/DecodingError.swift index 32edd83..44605a8 100644 --- a/Sources/JSONUtilities/DecodingError.swift +++ b/Sources/JSONUtilities/DecodingError.swift @@ -81,3 +81,6 @@ public struct DecodingError: Error, CustomStringConvertible, CustomDebugStringCo } } } + +// The dictionary, array and values of an error are plain JSON values, which are never mutated. +extension DecodingError: @unchecked Sendable {} diff --git a/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift b/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift index 169fb35..cd24e9c 100644 --- a/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift +++ b/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift @@ -18,6 +18,13 @@ extension URL: JSONPrimitiveConvertible { /// /// - returns: Returns a URL if the input string was successfully converted to a URL public static func from(jsonValue: String) -> URL? { + #if canImport(Darwin) + // Since macOS 14 and iOS 17, URL(string:) percent-encodes invalid characters instead of failing. + // Keep rejecting invalid URL strings, as on older systems and on Linux. + if #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) { + return URL(string: jsonValue, encodingInvalidCharacters: false) + } + #endif return URL(string: jsonValue) } } diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index 90ce587..0000000 --- a/codecov.yml +++ /dev/null @@ -1,9 +0,0 @@ -comment: - layout: header, changes, diff -coverage: - ignore: - - Sources/JSONUtilities/Deprecations.swift - - Tests/.* - - NonSwiftPackageManagerTests/.* - status: - patch: false From 4e8e342279266f39c8397d6f4c08287d119a3362 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 13:09:54 +0000 Subject: [PATCH 2/5] Fix optional decoding functions recursing into themselves Optional variants returned `try? json(...)` without naming the non-optional type, so with Swift 5 try? flattening the compiler could pick the optional overload itself, recursing until the stack overflowed (seen on Linux with Swift 5.10). Name the type explicitly so the throwing overload is used. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01237XKu4FYZRdEg2D5963qC --- .../JSONUtilities/Dictionary+JSONKey.swift | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Sources/JSONUtilities/Dictionary+JSONKey.swift b/Sources/JSONUtilities/Dictionary+JSONKey.swift index 98e41a7..16ab81f 100644 --- a/Sources/JSONUtilities/Dictionary+JSONKey.swift +++ b/Sources/JSONUtilities/Dictionary+JSONKey.swift @@ -38,7 +38,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath) -> T? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as T } // MARK: [JSONRawType] @@ -48,7 +48,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [T]? { - return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) + return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) as [T] } // MARK: [String: Any] @@ -68,7 +68,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [JSONDictionary]? { - return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) + return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) as [JSONDictionary] } // MARK: [String: JSONObjectConvertible] @@ -127,7 +127,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [T]? { - return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) + return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) as [T] } // MARK: RawRepresentable @@ -143,7 +143,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath) -> T? where T.RawValue: JSONRawType { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as T } // MARK: [RawRepresentable] @@ -161,7 +161,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [T]? where T.RawValue: JSONRawType { - return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) + return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) as [T] } // MARK: [String: RawRepresentable] @@ -178,7 +178,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [K: T]? where T.RawValue: JSONRawType { - return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) + return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) as [K: T] } // MARK: JSONPrimitiveConvertible @@ -194,7 +194,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath) -> T? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as T } // MARK: [JSONPrimitiveConvertible] @@ -211,7 +211,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [T]? { - return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) + return try? json(atKeyPath: keyPath, invalidItemBehaviour: invalidItemBehaviour) as [T] } // MARK: [String: [RawRepresentable]] @@ -227,7 +227,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [T]]? where T.RawValue: JSONRawType { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [T]] } // MARK: [String: [JSONPrimitiveConvertible]] @@ -243,7 +243,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [T]] } // MARK: [String: [JSONObjectConvertible]] @@ -259,7 +259,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [T]] } // MARK: [String: [JSONRawType]] @@ -275,7 +275,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [T]] } // MARK: [String: [String: RawRepresentable]] @@ -291,7 +291,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [String: T]]? where T.RawValue: JSONRawType { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [String: T]] } // MARK: [String: [String: JSONPrimitiveConvertible]] @@ -307,7 +307,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [String: T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [String: T]] } // MARK: [String: [String: JSONObjectConvertible]] @@ -323,7 +323,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [String: T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [String: T]] } // MARK: [String: [String: JSONRawType]] @@ -339,7 +339,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [String: [String: T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [String: [String: T]] } // MARK: [[RawRepresentable]] @@ -361,7 +361,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [[T]]? where T.RawValue: JSONRawType { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [[T]] } // MARK: [[JSONPrimitiveConvertible]] @@ -384,7 +384,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [[T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [[T]] } // MARK: [[JSONRawType]] @@ -403,7 +403,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [[T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [[T]] } // MARK: [[JSONObjectConvertible]] @@ -423,7 +423,7 @@ extension Dictionary where Key: JSONKey { } public func json(atKeyPath keyPath: KeyPath, invalidItemBehaviour: InvalidItemBehaviour = .remove) -> [[T]]? { - return try? json(atKeyPath: keyPath) + return try? json(atKeyPath: keyPath) as [[T]] } } From bc4dda82fc98ff4c623a6d3c9eb3e9d3ab4e5e6b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 13:11:10 +0000 Subject: [PATCH 3/5] Compare JSON in tests by serialized form so they pass on Linux NSDictionary.isEqual compares bridged numbers and booleans differently on Linux Foundation, which failed testCorrectDecodingForMandatoryJSONOnParentWithChild. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01237XKu4FYZRdEg2D5963qC --- .../Helpers/Dictionary+Equatable.swift | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Tests/JSONUtilitiesTests/Helpers/Dictionary+Equatable.swift b/Tests/JSONUtilitiesTests/Helpers/Dictionary+Equatable.swift index f5bab49..f8ae8b9 100644 --- a/Tests/JSONUtilitiesTests/Helpers/Dictionary+Equatable.swift +++ b/Tests/JSONUtilitiesTests/Helpers/Dictionary+Equatable.swift @@ -8,24 +8,30 @@ import Foundation +// Compares JSON values by their serialized form, so that the result doesn't depend on how each platform's +// Foundation bridges numbers and booleans (NSDictionary.isEqual differs between Darwin and Linux) +private func jsonEqual(_ lhs: Any, _ rhs: Any) -> Bool { + guard let lhsData = try? JSONSerialization.data(withJSONObject: lhs, options: .sortedKeys), + let rhsData = try? JSONSerialization.data(withJSONObject: rhs, options: .sortedKeys) else { + return false + } + return lhsData == rhsData +} + public func == (lhs: [String: Any], rhs: [String: Any]) -> Bool { - return NSDictionary(dictionary: lhs).isEqual(to: rhs) + return jsonEqual(lhs, rhs) } public func == (lhs: [String: Any]?, rhs: [String: Any]?) -> Bool { guard let lhs = lhs, let rhs = rhs else { return false } - return NSDictionary(dictionary: lhs).isEqual(to: rhs) + return jsonEqual(lhs, rhs) } public func == (lhs: [[String: Any]], rhs: [[String: Any]]) -> Bool { - let lhsArray = NSArray(array: lhs) - let rhsArray = NSArray(array: rhs) - return lhsArray.isEqual(to: rhsArray as [AnyObject]) + return jsonEqual(lhs, rhs) } public func == (lhs: [[String: Any]]?, rhs: [[String: Any]]?) -> Bool { guard let lhs = lhs, let rhs = rhs else { return false } - let lhsArray = NSArray(array: lhs) - let rhsArray = NSArray(array: rhs) - return lhsArray.isEqual(to: rhsArray as [AnyObject]) + return jsonEqual(lhs, rhs) } From 6a91dadfb350d876237f262c8158f4cb2b7308d0 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 13:12:18 +0000 Subject: [PATCH 4/5] Reject invalid URL strings on Linux with Swift 6 too Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01237XKu4FYZRdEg2D5963qC --- .../JSONUtilities/URL+JSONPrimitiveConvertible.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift b/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift index cd24e9c..665bd71 100644 --- a/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift +++ b/Sources/JSONUtilities/URL+JSONPrimitiveConvertible.swift @@ -18,13 +18,17 @@ extension URL: JSONPrimitiveConvertible { /// /// - returns: Returns a URL if the input string was successfully converted to a URL public static func from(jsonValue: String) -> URL? { + // Since macOS 14, iOS 17 and Swift 6 on Linux, URL(string:) percent-encodes invalid characters instead of failing. + // Keep rejecting invalid URL strings, as on older systems. #if canImport(Darwin) - // Since macOS 14 and iOS 17, URL(string:) percent-encodes invalid characters instead of failing. - // Keep rejecting invalid URL strings, as on older systems and on Linux. if #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) { return URL(string: jsonValue, encodingInvalidCharacters: false) } - #endif return URL(string: jsonValue) + #elseif compiler(>=6.0) + return URL(string: jsonValue, encodingInvalidCharacters: false) + #else + return URL(string: jsonValue) + #endif } } From d00e8d9a8839a466fa82ce0f9e8a27260bfd3dff Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 06:31:48 +0000 Subject: [PATCH 5/5] Cancel superseded CI runs and time out stuck macOS jobs Superseded pushes left several macOS jobs queued at once, which run on a small shared pool. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01237XKu4FYZRdEg2D5963qC --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9164217..f4ff993 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,14 @@ on: push: branches: [master] pull_request: {} +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: macos: runs-on: macos-15 name: macOS + timeout-minutes: 20 steps: - uses: actions/checkout@v4 - name: Build