-
Notifications
You must be signed in to change notification settings - Fork 61
fix: Calculators prohibit input of Chinese text. #189
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: master
Are you sure you want to change the base?
Conversation
log: Optimize filtering rules to exclude Chinese bug: https://pms.uniontech.com/bug-view-344067.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRestricts calculator input filtering to allow only digits, ASCII English letters, and a defined set of operator/symbol characters, explicitly excluding Chinese characters that were previously admitted via QChar::isLetter(). Class diagram for InputEdit with updated handleTextChanged filteringclassDiagram
class InputEdit {
+void handleTextChanged(text: QString)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来对这段代码进行审查:
改进建议:
static const QString allowedStatic = QString::fromUtf8("+-×÷.,%()/:^!");
bool isEnglishLetter = (ch.unicode() >= 'A' && ch.unicode() <= 'Z') ||
(ch.unicode() >= 'a' && ch.unicode() <= 'z');
bool InputEdit::isAllowedChar(const QChar& ch) const {
bool isEnglishLetter = (ch.unicode() >= 'A' && ch.unicode() <= 'Z') ||
(ch.unicode() >= 'a' && ch.unicode() <= 'z');
return ch.isDigit() || isEnglishLetter || allowedStatic.contains(ch) ||
decSym.contains(ch) || grpSym.contains(ch);
}
总体来说,这段代码质量良好,改进建议主要是为了提高代码的可维护性和性能。 |
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.
Hey - I've found 1 issue, and left some high level feedback:
- The ASCII range check for English letters works but is a bit ad hoc; consider using
ch.isLatin1()combined withch.isLetter()(and possibly an explicitQChar::Script_Latincheck if available) to more clearly and robustly express the intent to allow only Latin letters while excluding Chinese. - To avoid duplicating this logic if similar filtering is needed elsewhere, you might extract the "is allowed character" check into a small helper function or lambda, which will also make the loop body easier to read.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The ASCII range check for English letters works but is a bit ad hoc; consider using `ch.isLatin1()` combined with `ch.isLetter()` (and possibly an explicit `QChar::Script_Latin` check if available) to more clearly and robustly express the intent to allow only Latin letters while excluding Chinese.
- To avoid duplicating this logic if similar filtering is needed elsewhere, you might extract the "is allowed character" check into a small helper function or lambda, which will also make the loop body easier to read.
## Individual Comments
### Comment 1
<location> `src/widgets/inputedit.cpp:551-552` </location>
<code_context>
filtered.reserve(reformatStr.size());
for (const QChar &ch : std::as_const(reformatStr)) {
- if (ch.isDigit() || ch.isLetter() || allowedStatic.contains(ch) || decSym.contains(ch) || grpSym.contains(ch)) {
+ bool isEnglishLetter = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
+ if (ch.isDigit() || isEnglishLetter || allowedStatic.contains(ch) || decSym.contains(ch) || grpSym.contains(ch)) {
filtered.append(ch);
}
</code_context>
<issue_to_address>
**question:** Clarify whether restricting letters to ASCII only is intentional; consider whether extended Latin letters should be accepted.
This change now only accepts ASCII A–Z/a–z and rejects extended Latin characters like `é`, `ø`, `ß` or full-width Latin letters that `ch.isLetter()` previously allowed. If non-ASCII Latin input is expected, consider a broader condition (e.g. `QChar::isLatin1()` or another Unicode-aware check) rather than a pure ASCII range.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JWWTSL, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
log: Optimize filtering rules to exclude Chinese
bug: https://pms.uniontech.com/bug-view-344067.html
Summary by Sourcery
Bug Fixes: