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 bundle path check to handle symbolic links (close #858) #859

Merged
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
14 changes: 10 additions & 4 deletions Sources/Core/ScreenViewTracking/UIKitScreenViewTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ extension UIViewController {
@objc func sp_viewDidAppear(_ animated: Bool) {
sp_viewDidAppear(animated)

let bundle = Bundle(for: self.classForCoder)
if !bundle.bundlePath.hasPrefix(Bundle.main.bundlePath) {
// Ignore view controllers that don't start with the main bundle path
let bundleURL = Bundle(for: self.classForCoder).bundleURL
let mainBundleURL = Bundle.main.bundleURL

// Resolve any symbolic links and standardize the file paths
let resolvedBundlePath = bundleURL.resolvingSymlinksInPath().path
let resolvedMainBundlePath = mainBundleURL.resolvingSymlinksInPath().path

// Ignore view controllers that don't start with the main bundle path
guard resolvedBundlePath.hasPrefix(resolvedMainBundlePath) else {
return
}

Expand All @@ -81,7 +87,7 @@ extension UIViewController {
// Construct userInfo
var userInfo: [AnyHashable : Any] = [:]
userInfo["viewControllerClassName"] = String(describing: self.classForCoder)
userInfo["topViewControllerClassName"] = String(describing: top.self.classForCoder)
userInfo["topViewControllerClassName"] = String(describing: top.classForCoder)

// `name` is set to snowplowId class instance variable if it exists (hence no @"id" in userInfo)
userInfo["name"] = _SP_getName(self) ?? _SP_getName(top) ?? "Unknown"
Expand Down