Skip to content

Commit

Permalink
Truncate language in platform context entity to max 8 characters (close
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Jun 30, 2023
1 parent 8e9947f commit 1772b67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sources/Core/Subject/PlatformContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class PlatformContext {
platformDict[kSPMobileResolution] = deviceInfoMonitor.resolution
}
if shouldTrack(.language) {
platformDict[kSPMobileLanguage] = deviceInfoMonitor.language
// the schema has a max-length 8 for language which iOS exceeds sometimes
if let language = deviceInfoMonitor.language { platformDict[kSPMobileLanguage] = String(language.prefix(8)) }
}
if shouldTrack(.scale) {
platformDict[kSPMobileScale] = deviceInfoMonitor.scale
Expand Down
11 changes: 11 additions & 0 deletions Tests/TestPlatformContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ class TestPlatformContext: XCTestCase {
XCTAssertNil(platformDict[kSPMobileAppleIdfa])
XCTAssertNil(platformDict[kSPMobileAppleIdfv])
}

func testTruncatesLanguageToMax8Chars() {
let deviceInfoMonitor = MockDeviceInfoMonitor()
deviceInfoMonitor.language = "1234567890"
let context = PlatformContext(mobileDictUpdateFrequency: 0, networkDictUpdateFrequency: 1, deviceInfoMonitor: deviceInfoMonitor)
let platformDict = context.fetchPlatformDict(
userAnonymisation: true,
advertisingIdentifierRetriever: { UUID() }
)
XCTAssertEqual("12345678", platformDict[kSPMobileLanguage] as? String)
}
#endif

func testOnlyAddsRequestedProperties() {
Expand Down
4 changes: 3 additions & 1 deletion Tests/Utils/MockDeviceInfoMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ class MockDeviceInfoMonitor: DeviceInfoMonitor {
return 2.0
}

private var _language: String? = "EN"
override var language: String? {
return "EN"
get { return _language }
set { _language = newValue }
}

func accessCount(_ method: String) -> Int {
Expand Down

0 comments on commit 1772b67

Please sign in to comment.