fix: entity naming regex escaping, visibility division-by-zero, widget null guard - #42033
fix: entity naming regex escaping, visibility division-by-zero, widget null guard#42033PedroHenrique0713 wants to merge 1 commit into
Conversation
… lookup fix(AppsmithUtils): escape regex special characters in getNextEntityName and getDuplicateName. Entity name prefixes containing regex metacharacters (. $ * + etc.) caused incorrect auto-increment numbering and potential name collisions. fix(helpers): guard against division by zero in isElementVisibleInContainer. When an element has zero dimensions, elementArea === 0 caused Infinity/NaN comparisons that falsely reported the element as visible. fix(helpers): add null guard to getWidgetElementToScroll. Accessing widget.parentId without checking if canvasWidgets[widgetId] exists caused TypeError on stale/deleted widget IDs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughChangesUtility safety fixes
Estimated code review effort: 1 (Trivial) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected. |
|
Still active, and still applicable to The PR is three small independent fixes in two utility files:
The branch is mergeable and the checks are green. Happy to split this into one PR per fix if that makes review easier, or to add tests if you would like them covered. |
Summary
Three utility bug fixes in the Appsmith frontend.
1. Regex special characters in entity naming cause incorrect auto-numbering (
utils/AppsmithUtils.tsx)getNextEntityNameandgetDuplicateNameconstructnew RegExp(^${prefix}(\d+)$)without escaping regex metacharacters in the prefix. If a widget/entity name prefix contains.,$,*,+,?,^,{,},(,),[,],|, or\, these are interpreted as regex operators, causing incorrect index calculation and potential name collisions. Fix: escape regex special characters before constructing the pattern.2. Division by zero in
isElementVisibleInContainer(utils/helpers.tsx)When an element has zero dimensions (hidden via
display:none, not yet rendered, or 0px width/height),elementAreais0. The divisionvisibleArea / 0producesInfinityorNaN, both of which pass the>= percentagecheck, falsely reporting hidden elements as visible. Fix: returnfalsewhenelementArea === 0.3. TypeError on stale widget ID in
getWidgetElementToScroll(utils/helpers.tsx)canvasWidgets[widgetId]returnsundefinedif the widget was deleted between URL parsing and the deferredrequestIdleCallbackscroll handler. Accessing.parentIdonundefinedthrows an uncaught TypeError. Fix: returnnullwhen widget is not found.Testing
Summary by CodeRabbit