Skip to content
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

feat: Panel aliases support common special characters #7654

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/views/setting/panel/name/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function checkPanelName(rule: any, value: any, callback: any) {
if (value === '') {
return callback(new Error(i18n.global.t('setting.titleHelper')));
}
const reg = /^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-zA-Z0-9_ .\u4e00-\u9fa5-]{2,29}$/;
const reg = /^[a-zA-Z0-9\u4e00-\u9fa5 .,:!@#%&^*_+[\]{}~\-=?,。!|?:;「」『』【】()《》·]{3,30}$/;
if (!reg.test(value)) {
return callback(new Error(i18n.global.t('setting.titleHelper')));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression in your function has been modified to allow more characters, such as punctuation marks and symbols. While this might be necessary based on specific requirements, it may also result in validation errors that were previously acceptable due to the stricter pattern defined initially. It's recommended to thoroughly test with various inputs (including edge cases) to ensure correct functionality.

Additionally, consider adding a comment explanation of why the change was made, especially since reg is reused elsewhere in your codebase. This could help maintain clarity for other developers who work on this part of the code in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code difference introduces an updated regex pattern that allows alphanumeric characters including some special symbols such as .,:!@#%&^*_+\[\]{}~-=?,。!|?:;「」『』【】()《》·. This change aims to allow a wider range of valid panel name inputs beyond just letters, numbers, and underscores. The main consideration is security; allowing these additional punctuation marks could potentially be exploited inappropriately to bypass legitimate input validation checks.

Optimization suggestion:
It may be worth considering whether the current requirement to have at least two characters and up to thirty is necessary given the flexibility with new allowed characters. Simplifying this condition could make it clearer without losing significant functionality.

Potential issue:
Allowing more complex patterns might increase complexity when integrating with other parts of the application or services where strict rules on character usage are required.

"change": {
  "regex": "^\\w{3,30}$
}

This would restrict the rule to only accept words consisting of alphanumeric characters and underscore, which aligns closely with common naming conventions used across many systems and applications while maintaining minimal risk and simplicity of integration into existing workflows.

Expand Down
Loading