Strip all whitespace from pasted IDs, not only spaces (#16762)

This commit is contained in:
Joel Town Road authored and GitHub committed 2026-10-30 10:05:56 +08:00
1 parent e1ca09766c
commit cda3847337
2 files changed
+51 -2

No files matched your search

@@ -33,8 +33,13 @@ class IDTextInputFormatter extends TextInputFormatter {
}
}
// Pasted IDs can carry a trailing newline or tab (e.g. copied from a
// spreadsheet cell) or non-breaking spaces, so strip all whitespace, not only
// plain spaces.
final _whitespace = RegExp(r'\s');
String formatID(String id) {
String id2 = id.replaceAll(' ', '');
String id2 = id.replaceAll(_whitespace, '');
String suffix = '';
if (id2.endsWith(r'\r') || id2.endsWith(r'/r')) {
suffix = id2.substring(id2.length - 2, id2.length);
@@ -56,5 +61,5 @@ String formatID(String id) {
}
String trimID(String id) {
return id.replaceAll(' ', '');
return id.replaceAll(_whitespace, '');
}