Skip to content

Commit

Permalink
Update ExpiryDateEditText allowlist
Browse files Browse the repository at this point in the history
Only allow digits and the `/` by setting the input type to `number`
and setting `android:digits` to the allowlist.

This prevents `.` and `-` from being entered as input.

Fixes #2972
  • Loading branch information
mshafrir-stripe committed Oct 27, 2020
1 parent 48bc353 commit deaacc9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions stripe/res/layout/card_input_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:imeOptions="actionNext"
android:inputType="date"
android:maxLength="5"
android:digits="@string/stripe_expiration_date_allowlist"
android:hint="@string/expiry_date_hint"
style="@style/Stripe.CardInputWidget.EditText"
/>
Expand Down
3 changes: 1 addition & 2 deletions stripe/res/layout/card_multiline_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="date"
android:maxLength="@integer/stripe_date_length"
android:digits="@string/stripe_expiration_date_allowlist"
android:nextFocusDown="@+id/et_cvc"
android:nextFocusForward="@+id/et_cvc"
/>
Expand Down
1 change: 1 addition & 0 deletions stripe/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="cvc_amex_hint">CVV</string>
<string name="cvc_multiline_helper">123</string>
<string name="cvc_multiline_helper_amex">1234</string>
<string name="stripe_expiration_date_allowlist">0123456789/</string>
<string name="zip_helper">12345</string>
<string name="paymentsheet_payment_method_item_card_number" translatable="false">····%1$s</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.stripe.android.view
import android.content.Context
import android.os.Build
import android.text.Editable
import android.text.InputFilter
import android.text.InputType
import android.util.AttributeSet
import android.view.View
import android.widget.EditText
Expand All @@ -20,6 +22,13 @@ class ExpiryDateEditText @JvmOverloads constructor(
) : StripeEditText(context, attrs, defStyleAttr) {

init {
inputType = InputType.TYPE_CLASS_NUMBER
filters = listOf(
InputFilter.LengthFilter(
context.resources.getInteger(R.integer.stripe_date_length)
)
).toTypedArray()

setErrorMessage(resources.getString(R.string.invalid_expiry_year))
listenForTextChanges()

Expand Down

0 comments on commit deaacc9

Please sign in to comment.