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 issue with limited postal code input #5715

Merged
merged 1 commit into from
Oct 17, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Payments

* [FIXED][5701](https://github.com/stripe/stripe-android/pull/5701) Treat blank fields as invalid in `ShippingInfoWidget`.
* [FIXED][5715](https://github.com/stripe/stripe-android/pull/5715) Postal codes for countries other than US and Canada are no longer limited to a single character.

## 20.15.0 - 2022-10-11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ internal class PostalCodeConfig(

override fun getError(): FieldError? {
return when {
input.isNotBlank() && !isFull() && country == "US" -> {
input.isNotBlank() && !isValid() && country == "US" -> {
FieldError(R.string.address_zip_invalid)
}
input.isNotBlank() && !isFull() -> {
input.isNotBlank() && !isValid() -> {
FieldError(R.string.address_zip_postal_invalid)
}
else -> null
}
}

override fun isFull(): Boolean = input.length >= format.minimumLength
override fun isFull(): Boolean = input.length >= format.maximumLength
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this doesn’t impact the resolution of the issue, it makes more sense to me than the previous implementation: A field is full when it reaches the maximum length, not when it exceeds the minimum length.


override fun isBlank(): Boolean = input.isBlank()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class PostalCodeConfigTest {
Truth.assertThat(determineStateForInput(" ").isValid()).isFalse()
Truth.assertThat(determineStateForInput(" ").isFull()).isFalse()
Truth.assertThat(determineStateForInput("a").isValid()).isTrue()
Truth.assertThat(determineStateForInput("a").isFull()).isTrue()
Truth.assertThat(determineStateForInput("a").isFull()).isFalse()
Truth.assertThat(determineStateForInput("1").isValid()).isTrue()
Truth.assertThat(determineStateForInput("1").isFull()).isTrue()
Truth.assertThat(determineStateForInput("1").isFull()).isFalse()
Truth.assertThat(determineStateForInput("aaaaaa").isValid()).isTrue()
Truth.assertThat(determineStateForInput("111111").isValid()).isTrue()
}
Expand Down