Skip to content

Commit

Permalink
Fix infinite recursion when casting AnySerializable to wrong type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
leoMehlig authored Sep 3, 2023
1 parent bd14dae commit 03d5386
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Defaults/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ extension Defaults.Serializable {
return anyObject
}

guard let nextType = T.Serializable.self as? any Defaults.Serializable.Type else {
guard let nextType = T.Serializable.self as? any Defaults.Serializable.Type, nextType != T.self else {
// This is a special case for the types which do not conform to `Defaults.Serializable` (for example, `Any`).
return T.bridge.deserialize(anyObject as? T.Serializable) as? T
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,10 @@ final class DefaultsAnySerializableTests: XCTestCase {

waitForExpectations(timeout: 10)
}

Check warning on line 469 in Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func testWrongCast() {
let value = Defaults.AnySerializable(false)
XCTAssertEqual(value.get(Bool.self), false)

Check warning on line 472 in Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift

View workflow job for this annotation

GitHub Actions / lint

XCTest Specific Matcher Violation: Prefer the specific matcher 'XCTAssertFalse' instead (xct_specific_matcher)
XCTAssertNil(value.get(String.self))
}
}

0 comments on commit 03d5386

Please sign in to comment.