-
Notifications
You must be signed in to change notification settings - Fork 597
Improvements Over Path check in Regex #5830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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\.)'); | ||||||
|
||||||
| final urlPattern = RegExp(r'^(https?:\/\/|www\.)'); | |
| final urlPattern = RegExp(r'^(https?:\/\/.+|www\..+)'); |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Trailing whitespace detected at the end of the comment. Consider removing it for cleaner code.
| r'(~?\/|\.\/|\.\.\/)?([^\/:*?"<>|\r\n]+\/)*[^\/:*?"<>|\r\n]*' // Unix paths | |
| r'(~?\/|\.\/|\.\.\/)?([^\/:*?"<>|\r\n]+\/)*[^\/:*?"<>|\r\n]*' // Unix paths |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new file path regex can match empty strings, which is likely unintended. For example:
- The Windows path pattern
([a-zA-Z]:\\|\\\\)?([^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*has optional components that can all be empty - The Unix path pattern
(~?\/|\.\/|\.\.\/)?([^\/:*?"<>|\r\n]+\/)*[^\/:*?"<>|\r\n]*also has optional components with*quantifiers allowing zero matches
This means isUrlOrPath("") would return true, which is probably not the desired behavior. Consider using + instead of * for the final character class in each path pattern, or adding a length check before the regex matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
isUrlOrPathlacks documentation explaining its purpose, parameters, return value, and expected behavior. Given the complexity of the new regex patterns and the specific exclusions mentioned in the PR description (URLs, base64, invalid characters), adding a doc comment would improve maintainability. For example: