Skip to content
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: 1 addition & 1 deletion .github/badges/branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

The changelog for `Superwall`. Also see the [releases](https://github.com/superwall/Superwall-Android/releases) on GitHub.

## 2.7.13

## Fixes
- Fix `device.appVersionPadded` and `device.sdkVersionPadded` emitting non-ASCII digits on devices whose default locale uses a non-Latin numbering system (e.g. `ar-EG`, `fa-IR`, `bn-BD`), which caused audience-rule version comparisons to misbucket affected users.

## 2.7.12

## Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class DeviceHelper(
}
}

private fun String.asPadded(): String {
internal fun String.asPadded(): String {
val components = split("-")
if (components.isEmpty()) {
return ""
Expand All @@ -673,7 +673,7 @@ private fun String.asPadded(): String {
// Pad beta number and add to appendix
if (appendixComponents.size > 1) {
appendixVersion =
String.format("%03d", appendixComponents[1].toIntOrNull() ?: 0)
String.format(Locale.US, "%03d", appendixComponents[1].toIntOrNull() ?: 0)
appendix += ".$appendixVersion"
}
}
Expand All @@ -682,15 +682,15 @@ private fun String.asPadded(): String {
val versionComponents = versionNumber.split(".")
var newVersion = ""
if (versionComponents.isNotEmpty()) {
val major = String.format("%03d", versionComponents[0].toIntOrNull() ?: 0)
val major = String.format(Locale.US, "%03d", versionComponents[0].toIntOrNull() ?: 0)
newVersion += major
}
if (versionComponents.size > 1) {
val minor = String.format("%03d", versionComponents[1].toIntOrNull() ?: 0)
val minor = String.format(Locale.US, "%03d", versionComponents[1].toIntOrNull() ?: 0)
newVersion += ".$minor"
}
if (versionComponents.size > 2) {
val patch = String.format("%03d", versionComponents[2].toIntOrNull() ?: 0)
val patch = String.format(Locale.US, "%03d", versionComponents[2].toIntOrNull() ?: 0)
newVersion += ".$patch"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.superwall.sdk.network.device

import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import java.util.Locale

class DeviceHelperAsPaddedTest {
private lateinit var previousLocale: Locale

@Before
fun setUp() {
previousLocale = Locale.getDefault()
}

@After
fun tearDown() {
Locale.setDefault(previousLocale)
}

@Test
fun `pads major, minor and patch with ASCII digits under en-US locale`() {
Locale.setDefault(Locale.US)
assertEquals("000.000.003", "0.0.3".asPadded())
assertEquals("001.002.003", "1.2.3".asPadded())
assertEquals("012.034.056", "12.34.56".asPadded())
}

@Test
fun `keeps ASCII digits when default locale renders digits as Arabic-Indic`() {
Locale.setDefault(Locale.forLanguageTag("ar-EG"))
assertEquals("000.000.003", "0.0.3".asPadded())
assertEquals("001.002.003", "1.2.3".asPadded())
}

@Test
fun `keeps ASCII digits when default locale renders digits as Extended Arabic-Indic`() {
Locale.setDefault(Locale.forLanguageTag("fa-IR"))
assertEquals("000.000.003", "0.0.3".asPadded())
}

@Test
fun `keeps ASCII digits when default locale renders digits as Bengali`() {
Locale.setDefault(Locale.forLanguageTag("bn-BD"))
assertEquals("000.000.003", "0.0.3".asPadded())
}

@Test
fun `pads beta appendix numerically with ASCII digits under non-Latin locale`() {
Locale.setDefault(Locale.forLanguageTag("ar-EG"))
assertEquals("001.002.003-beta.004", "1.2.3-beta.4".asPadded())
}

@Test
fun `preserves non-numeric appendix without a dot`() {
Locale.setDefault(Locale.forLanguageTag("ar-EG"))
assertEquals("001.002.003-rc", "1.2.3-rc".asPadded())
}
}