Skip to content

Commit 6e7a814

Browse files
zhu-xiaoweixiaoweii
andauthored
fix: crash when user attribute is empty (#71)
Co-authored-by: xiaoweii <xiaoweii@amazom.com>
1 parent 45a4ad4 commit 6e7a814

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

IntegrationTest/devicefarm/logcat_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_app_end(self, path):
196196
def get_submitted_events(path):
197197
submitted_events = []
198198
with open(path, 'r') as file:
199-
pattern = re.compile(r' Send (\d+) events')
199+
pattern = re.compile(r'^Send (\d+) events')
200200
for line in file:
201201
match = pattern.search(line)
202202
if match:
@@ -209,7 +209,7 @@ def get_recorded_events(path):
209209
log_lines = file.readlines()
210210
events = []
211211
first_event_pattern = re.compile(r'app_event_log:Saved event (\w+):(.*)$')
212-
event_pattern = re.compile(r' Saved event (\w+):(.*)$')
212+
event_pattern = re.compile(r'^Saved event (\w+):(.*)$')
213213

214214
current_event_name = ''
215215

Sources/Clickstream/Dependency/Clickstream/Event/ClickstreamEvent.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ class ClickstreamEvent: AnalyticsPropertiesModel {
109109
if !items.isEmpty {
110110
event["items"] = items
111111
}
112-
event["user"] = userAttributes
112+
if !userAttributes.isEmpty {
113+
event["user"] = userAttributes
114+
}
113115
event["attributes"] = getAttributeObject(from: attributes)
114116
return event
115117
}

Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class EventRecorderTest: XCTestCase {
132132
XCTAssertNotNil(event["app_version"])
133133
XCTAssertNotNil(event["app_package_name"])
134134
XCTAssertNotNil(event["app_title"])
135-
XCTAssertNotNil(event["user"])
135+
XCTAssertNil(event["user"])
136136
XCTAssertNotNil(event["attributes"])
137137
XCTAssertNil(event["noneExistAttribute"])
138138
}

Tests/ClickstreamTests/IntegrationTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class IntegrationTest: XCTestCase {
256256
XCTAssertEqual((user["score"] as! JsonObject)["value"] as! Double, 85.2)
257257
XCTAssertEqual((user["_user_name"] as! JsonObject)["value"] as! String, "carl")
258258
XCTAssertNotNil(user[Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP])
259+
XCTAssertNotNil((user[Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP] as! JsonObject)["value"])
259260
}
260261

261262
func testProfileSetTimestamp() throws {

0 commit comments

Comments
 (0)