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

fix(utils): crash when dealing with colors from storyboard #229

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- fix crash when loading dynamic colors from storyboards ([#229](https://github.com/PostHog/posthog-ios/pull/229))

## 3.13.3 - 2024-10-25

- fix race condition in PostHogFileBackedQueue.deleteFiles ([#218](https://github.com/PostHog/posthog-ios/pull/218))
Expand Down
9 changes: 8 additions & 1 deletion PostHog/Replay/CGColor+Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@

extension CGColor {
func toRGBString() -> String? {
guard let components = components, components.count >= 3 else {
// see dicussion: https://github.com/PostHog/posthog-ios/issues/226
// Allow only CGColors with an intiialized value of `numberOfComponents` with a value in 3...4 range
// Loading dynamic colors from storyboard sometimes leads to some random values for numberOfComponents like `105553118884896` which crashes the app
guard
3 ... 4 ~= numberOfComponents, // check range
let components = components, // we now assume it's safe to access `components`
components.count >= 3
else {
return nil
}

Expand Down
Loading