Skip to content

Commit

Permalink
fix(gui): Remove spaces from the Pro token input field (#875)
Browse files Browse the repository at this point in the history
Sometimes copy-pasting a pro token comes with trailing spaces. Neither
leading, trailing or even middle spaces are alloweable in a token. This
PR leverages Flutter builtin mechanisms to filter input supplied to the
token text field such that any kind of whitespaces (not only the ASCII
ones) are discarded before any further processing.

Closes #857 

---

I'm purposefully basing this PR on top of #873 so I can stress CI to
exercise the changes therein introduced. There is no dependency between
the two tasks.

---
UDENG-3810
  • Loading branch information
CarlosNihelton authored Aug 21, 2024
2 parents 0518a41 + a87eac5 commit 0e4126b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dart_either/dart_either.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:yaru/yaru.dart';
import '../../core/either_value_notifier.dart';
Expand Down Expand Up @@ -78,6 +79,10 @@ class _ProTokenInputFieldState extends State<ProTokenInputField> {
children: [
Expanded(
child: TextField(
inputFormatters: [
// This ignores all sorts of (Unicode) whitespaces (not only at the ends).
FilteringTextInputFormatter.deny(RegExp(r'\s')),
],
autofocus: false,
controller: _controller,
decoration: InputDecoration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ void main() {
final input = tester.firstWidget<TextField>(inputField);
expect(input.decoration!.errorText, isNull);

final button =
tester.firstWidget<ElevatedButton>(find.byType(ElevatedButton));
expect(button.enabled, isTrue);
});
testWidgets('good token with spaces', (tester) async {
await tester.pumpWidget(theApp);
final inputField = find.byType(TextField);

await tester.enterText(
inputField,
// good token plus a bunch of types of white spaces.
' ${tks.good} \u{00A0}\u{2000}\u{2002}\u{202F}\u{205F}\u{3000} ',
);
await tester.pump();

final input = tester.firstWidget<TextField>(inputField);
expect(input.decoration!.errorText, isNull);

final button =
tester.firstWidget<ElevatedButton>(find.byType(ElevatedButton));
expect(button.enabled, isTrue);
Expand Down

0 comments on commit 0e4126b

Please sign in to comment.