-
-
Notifications
You must be signed in to change notification settings - Fork 385
feat(IpAddress): paste url support port #7377
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,15 +95,22 @@ export function init(id, invoke) { | |||||||
| if (!raw) { | ||||||||
| return; | ||||||||
| } | ||||||||
| const parts = raw.replace(/[^\d.]/g, '').split('.').filter(p => p.length); | ||||||||
|
|
||||||||
| const ipRegex = /\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/; | ||||||||
| const match = raw.match(ipRegex); | ||||||||
| const parts = match ? match[0] : null; | ||||||||
| if (parts === null) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
Comment on lines
+99
to
+104
|
||||||||
|
|
||||||||
| const cells = el.querySelectorAll(".ipv4-cell"); | ||||||||
| let pos = 0; | ||||||||
| const args = []; | ||||||||
| parts.forEach(p => { | ||||||||
| parts.split('.').forEach(p => { | ||||||||
| if (pos > 3) { | ||||||||
| return; | ||||||||
| } | ||||||||
| const num = Math.max(0, Math.min(255, parseInt(p, 10) || 0)); | ||||||||
| const num = parseInt(p, 10); | ||||||||
|
||||||||
| const num = parseInt(p, 10); | |
| const parsed = parseInt(p, 10); | |
| const num = Math.max(0, Math.min(255, isNaN(parsed) ? 0 : parsed)); |
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 IP address regex pattern is complex and should be extracted to a constant at the module level with a descriptive name like IP_ADDRESS_PATTERN. This improves code maintainability by making the pattern reusable and easier to test or modify. The regex could also use a comment explaining its purpose of extracting valid IPv4 addresses from text that may contain additional content like ports.