Fix cannot auto create tag when paste list email and switch focus

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-03-10 16:24:47 +07:00
committed by Dat H. Pham
parent 0e2ea6a635
commit 36a9117e00
4 changed files with 63 additions and 49 deletions
+14 -6
View File
@@ -6,7 +6,7 @@ import 'package:core/domain/exceptions/string_exception.dart';
import 'package:http_parser/http_parser.dart';
class StringConvert {
static const String separatorPattern = r'[ ,;]+';
static const String emailSeparatorPattern = r'[,;]+';
static String? writeEmptyToNull(String text) {
if (text.isEmpty) return null;
@@ -26,23 +26,28 @@ class StringConvert {
}
}
static List<String> extractStrings(String input) {
static List<String> extractStrings(String input, String separatorPattern) {
try {
// Check if the input is URL encoded
if (input.contains('%')) {
input = Uri.decodeComponent(input); // Decode URL encoding
}
// Check if the input is Base64 encoded
if (input.length % 4 == 0 && RegExp(r'^[A-Za-z0-9+/=]+$').hasMatch(input)) {
input = utf8.decode(base64.decode(input)); // Decode Base64 encoding
// Efficient Base64 validation: Check length and minimal regex match
if (input.length % 4 == 0 && input.contains(RegExp(r'^[A-Za-z0-9+/=]+$'))) {
try {
input = utf8.decode(base64.decode(input)); // Decode Base64 encoding
} catch (_) {
// Ignore if decoding fails
}
}
final RegExp separator = RegExp(separatorPattern);
final listStrings = input
.replaceAll('\n', ' ')
.split(separator)
.where((value) => value.trim().isNotEmpty)
.map((value) => value.trim())
.where((value) => value.isNotEmpty)
.toList();
log('StringConvert::extractStrings:listStrings = $listStrings');
return listStrings;
@@ -51,6 +56,9 @@ class StringConvert {
}
}
static List<String> extractEmailAddress(String input) =>
extractStrings(input, emailSeparatorPattern);
static String decodeFromBytes(
Uint8List bytes, {
required String? charset,