-
-
Notifications
You must be signed in to change notification settings - Fork 382
feat(IpAddress): support paste function #7276
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
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import Data from "../../modules/data.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import Data from "../../modules/data.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import EventHandler from "../../modules/event-handler.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const selectCell = (el, index) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -73,7 +73,7 @@ export function init(id) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| e.preventDefault() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| selectCell(el, index - 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (e.key === 'Delete' || e.key === 'Tab' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (e.composed || e.key === 'Delete' || e.key === 'Tab' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (e.composed || e.key === 'Delete' || e.key === 'Tab' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') { | |
| else if (e.key === 'Delete' || e.key === 'Tab' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') { |
Copilot
AI
Dec 9, 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 'paste' event handler is not being cleaned up in the dispose function (lines 115-125). This creates a memory leak as the event listener will persist after the component is disposed.
The dispose function should include:
EventHandler.off(c, 'paste')
Copilot
AI
Dec 9, 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 regex /[^\d.]/g allows multiple consecutive dots and doesn't validate IP address format. For example, "192...168" would be parsed as ["192", "168"], silently ignoring the malformed input. Consider adding validation or using a more robust parsing approach that validates IP address format before processing.
| const parts = raw.replace(/[^\d.]/g, '').split('.').filter(p => p.length); | |
| const cells = el.querySelectorAll(".ipv4-cell"); | |
| let pos = 0; | |
| parts.forEach(p => { | |
| if (pos > 3) { | |
| return; | |
| } | |
| const num = Math.max(0, Math.min(255, parseInt(p, 10) || 0)); | |
| cells[pos].value = num.toString(); | |
| ip.prevValues[pos] = cells[pos].value; | |
| pos++; | |
| }); | |
| // Validate IPv4 address format: four octets, each 0-255, separated by dots | |
| const ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/; | |
| if (!ipv4Regex.test(raw.trim())) { | |
| // Invalid IP address format; ignore paste | |
| return; | |
| } | |
| const parts = raw.trim().split('.'); | |
| const cells = el.querySelectorAll(".ipv4-cell"); | |
| for (let pos = 0; pos < 4; pos++) { | |
| cells[pos].value = parts[pos]; | |
| ip.prevValues[pos] = cells[pos].value; | |
| } |
Copilot
AI
Dec 9, 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 paste event handler always starts pasting from position 0, ignoring which cell the user is actually focused on. When a user pastes "192.168" while focused on the second cell, it overwrites the first two cells instead of filling from the second cell onward.
Consider using the index parameter (available in the forEach scope) to start pasting from the currently focused cell:
let pos = index;
parts.forEach(p => {
if (pos > 3) {
return;
}
const num = Math.max(0, Math.min(255, parseInt(p, 10) || 0));
cells[pos].value = num.toString();
ip.prevValues[pos] = cells[pos].value;
pos++;
});
Uh oh!
There was an error while loading. Please reload this page.