Repository navigation
fix: Preserve cached String values that look like Int64, UUID or Timestamp - #122
Conversation
There was a problem hiding this comment.
Code Review
This pull request ensures that string values resembling Int64, UUID, or Timestamp are not incorrectly rewritten in the client cache by verifying that re-encoding reproduces the exact original string. The feedback suggests improving safety by propagating errors instead of using force-try (try!) in the timestamp helper methods, and optimizing the decoding path in AnyCodableValue to avoid expensive exception throwing during type inference.
|
LGTM - thanks for the PR @dmorfav !! |
Thanks. The workflow runs (check, spm) are waiting for maintainer approval since this is my first contribution from a fork. |
|
@aashishpatil-g here too, the CI failure is unrelated to this change: FYI @paulb777 |
|
I’m keeping an eye on PR #124 so I can update mine once it’s merged. |
…ring-scalars # Conflicts: # CHANGELOG.md
|
hi @aashishpatil-g the PR is green and ready for review. |
|
LGTM - merging.. |
Fixes firebase/firebase-ios-sdk#16887
On cache hits,
AnyCodableValue.init(from:)infersTimestamp→Int64→ UUID for every JSON string, and the lenient parsers accept non-canonical input. Re-encoding then loses the original value:"08001"→"8001","+5"→"5", an uppercase hex string → lowercase, and a timestamp with an offset → UTC.Change
AnyCodableValue: infer.timestamp/.int64/.uuidonly if re-encoding gives back exactly the original string. Otherwise the value stays.string.CodableTimestamp: move the string formatting intoCodableTimestampHelperso that the round-trip check and the encoder use the same code.Canonical values sent by the server for
Int64,UUIDandTimestampfields still infer as before, soAnyValue.decodeValue(Int64.self)and the existing cache behavior stay the same. The cache schema does not change.Tests
AnyValueCodableTests: non-canonical strings keep their exact value, and canonical values are still inferred.CacheTests: a dehydrate/hydrate round trip throughSQLiteCacheProviderkeeps"08001"and"0012345678".swift test --filter FirebaseDataConnectUnitpasses (83 tests), and so doesscripts/style.sh test-only.