Skip to content
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
13 changes: 10 additions & 3 deletions src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Copy link

Copilot AI Dec 19, 2025

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.

Copilot uses AI. Check for mistakes.
const match = raw.match(ipRegex);
const parts = match ? match[0] : null;
if (parts === null) {
return;
}
Comment on lines +99 to +104
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The new paste behavior that extracts IP addresses from URLs with ports lacks test coverage. Tests should be added to verify that pasting values like "192.168.1.1:8080" correctly extracts "192.168.1.1", and that edge cases like malformed URLs, URLs without IPs, or multiple IPs are handled appropriately.

Copilot uses AI. Check for mistakes.

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);
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

Removing the Math.max and Math.min validation is unsafe. While the regex validates that matched IPs have octets in the 0-255 range, the parseInt on line 113 should still include fallback validation. The original code protected against any unexpected parsing issues by ensuring values are always bounded. Without the '|| 0' fallback, parseInt could theoretically return NaN in edge cases, and without the Math.min(255, ...) check, there's no defensive programming against future code changes. This defensive validation should be retained.

Suggested change
const num = parseInt(p, 10);
const parsed = parseInt(p, 10);
const num = Math.max(0, Math.min(255, isNaN(parsed) ? 0 : parsed));

Copilot uses AI. Check for mistakes.
args.push(num);
cells[pos].value = num.toString();
ip.prevValues[pos] = cells[pos].value;
Expand Down