From ea845d017b150e45966b9e6a3e456c8c4c3fd9ae Mon Sep 17 00:00:00 2001 From: Osama Mohammed Al-Zabidi <57198110+osamalzabidi@users.noreply.github.com> Date: Wed, 19 Nov 2025 01:48:58 +0300 Subject: [PATCH] Improvements Over Path check Regex 1. Allows spaces and special characters commonly found in paths 2. Platform-aware - distinguishes between Windows and Unix paths 3. Excludes invalid characters (*, ?, ", <, >, |) 4. Context-aware - considers file extensions and path structure 5. Better false-positive prevention - excludes URLs and base64 --- packages/flet/lib/src/utils/images.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/flet/lib/src/utils/images.dart b/packages/flet/lib/src/utils/images.dart index c87b867b7f..5fe56b41ac 100644 --- a/packages/flet/lib/src/utils/images.dart +++ b/packages/flet/lib/src/utils/images.dart @@ -91,13 +91,21 @@ bool isBase64ImageString(String value) { bool isUrlOrPath(String value) { // Check for URL pattern - final urlPattern = RegExp(r'^(http:\/\/|https:\/\/|www\.)'); + final urlPattern = RegExp(r'^(https?:\/\/|www\.)'); if (urlPattern.hasMatch(value)) { return true; } // Check for common file path characters - final filePathPattern = RegExp(r'^[a-zA-Z0-9_\-/\\\.]+$'); + final filePathPattern = RegExp( + r'^(' + r'([a-zA-Z]:\\|\\\\)?([^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*' // Windows paths + r'|' // OR + r'(~?\/|\.\/|\.\.\/)?([^\/:*?"<>|\r\n]+\/)*[^\/:*?"<>|\r\n]*' // Unix paths + r'|' // OR + r'[^\\/:*?"<>|\r\n]+' // Just filenames without path separators + r')$' + ); if (filePathPattern.hasMatch(value)) { return true; }