Skip to content

Commit

Permalink
Remove parsing of the OS version in case of web/desktop sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime NATUREL committed Oct 11, 2022
1 parent 8cd8c65 commit daa5f88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,38 +135,14 @@ class ParseDeviceUserAgentUseCase @Inject constructor() {
val secondSegment = deviceOperatingSystemSegments.getOrNull(1).orEmpty()

return when {
firstSegment.startsWith(OPERATING_SYSTEM_MAC_KEYWORD) -> {
// e.g. (Macintosh; Intel Mac OS X 10_15_7) => macOS 10.15.7
val version = secondSegment
.substringAfterLast(" ")
.replace("_", ".")
if (version.isEmpty()) {
OPERATING_SYSTEM_MAC
} else {
"$OPERATING_SYSTEM_MAC $version"
}
}
firstSegment.startsWith(OPERATING_SYSTEM_WINDOWS_KEYWORD) -> {
// e.g. (Windows NT 10.0; Win64; x64) => Windows 10.0
firstSegment.replace("NT ", "")
}
firstSegment.startsWith(DEVICE_IPAD_KEYWORD) || firstSegment.startsWith(DEVICE_IPHONE_KEYWORD) -> {
// e.g. (iPad; CPU OS 8_4_1 like Mac OS X) => macOS 8.4.1
val version = secondSegment
.split(" ")
.find { it.contains("_") }
?.replace("_", ".")
.orEmpty()
if (version.isEmpty()) {
OPERATING_SYSTEM_IOS
} else {
"$OPERATING_SYSTEM_IOS $version"
}
}
secondSegment.startsWith(OPERATING_SYSTEM_ANDROID_KEYWORD) -> {
// e.g. (Linux; Android 9; SM-G973U Build/PPR1.180610.011) => Android 9
secondSegment
}
// e.g. (Macintosh; Intel Mac OS X 10_15_7) => macOS
firstSegment.startsWith(OPERATING_SYSTEM_MAC_KEYWORD) -> OPERATING_SYSTEM_MAC
// e.g. (Windows NT 10.0; Win64; x64) => Windows
firstSegment.startsWith(OPERATING_SYSTEM_WINDOWS_KEYWORD) -> OPERATING_SYSTEM_WINDOWS_KEYWORD
// e.g. (iPad; CPU OS 8_4_1 like Mac OS X) => iOS
firstSegment.startsWith(DEVICE_IPAD_KEYWORD) || firstSegment.startsWith(DEVICE_IPHONE_KEYWORD) -> OPERATING_SYSTEM_IOS
// e.g. (Linux; Android 9; SM-G973U Build/PPR1.180610.011) => Android
secondSegment.startsWith(OPERATING_SYSTEM_ANDROID_KEYWORD) -> OPERATING_SYSTEM_ANDROID_KEYWORD
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private val A_USER_AGENT_LIST_FOR_DESKTOP = listOf(
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36",
)
private val AN_EXPECTED_RESULT_LIST_FOR_DESKTOP = listOf(
DeviceExtendedInfo(DeviceType.DESKTOP, null, "macOS 10.15.7", "Electron", "20.1.1"),
DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows 10.0", "Electron", "20.1.1"),
DeviceExtendedInfo(DeviceType.DESKTOP, null, "macOS", "Electron", "20.1.1"),
DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows", "Electron", "20.1.1"),
)

private val A_USER_AGENT_LIST_FOR_WEB = listOf(
Expand All @@ -78,15 +78,15 @@ private val A_USER_AGENT_LIST_FOR_WEB = listOf(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246",
)
private val AN_EXPECTED_RESULT_LIST_FOR_WEB = listOf(
DeviceExtendedInfo(DeviceType.WEB, null, "macOS 10.15.7", "Chrome", "104.0.5112.102"),
DeviceExtendedInfo(DeviceType.WEB, null, "Windows 10.0", "Chrome", "104.0.5112.102"),
DeviceExtendedInfo(DeviceType.WEB, null, "macOS 10.10", "Firefox", "39.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "macOS 10.10.2", "Safari", "8.0.3"),
DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", "Chrome", "69.0.3497.100"),
DeviceExtendedInfo(DeviceType.WEB, null, "iOS 8.4.1", "Safari", "8.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "iOS 8.4.1", "Safari", "8.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "Windows 6.0", "Firefox", "40.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "Windows 10.0", "Edge", "12.246"),
DeviceExtendedInfo(DeviceType.WEB, null, "macOS", "Chrome", "104.0.5112.102"),
DeviceExtendedInfo(DeviceType.WEB, null, "Windows", "Chrome", "104.0.5112.102"),
DeviceExtendedInfo(DeviceType.WEB, null, "macOS", "Firefox", "39.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "macOS", "Safari", "8.0.3"),
DeviceExtendedInfo(DeviceType.WEB, null, "Android", "Chrome", "69.0.3497.100"),
DeviceExtendedInfo(DeviceType.WEB, null, "iOS", "Safari", "8.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "iOS", "Safari", "8.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "Windows", "Firefox", "40.0"),
DeviceExtendedInfo(DeviceType.WEB, null, "Windows", "Edge", "12.246"),
)

private val AN_UNKNOWN_USER_AGENT_LIST = listOf(
Expand Down

0 comments on commit daa5f88

Please sign in to comment.