Skip to content

Commit ee8a764

Browse files
committed
Fix: copilot feedback
1 parent 153fddb commit ee8a764

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎Source/NETworkManager.Tests/Utilities/RegexHelperTests.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ public void HostnameOrDomain(string input, bool isMatch)
8080
[Theory]
8181
[InlineData("borntoberoot.net", true)]
8282
[InlineData("local.example.com", true)]
83+
[InlineData("server-01.example.com", true)]
84+
[InlineData("example.com.", true)]
8385
[InlineData("example", false)]
86+
[InlineData("example.c", false)]
87+
// A hyphen at the start or end of a label, like hostnames
88+
[InlineData("server.-bad-.com", false)]
89+
[InlineData("-example.com", false)]
90+
[InlineData("example-.com", false)]
8491
public void Domain(string input, bool isMatch)
8592
{
8693
Assert.Equal(isMatch, Regex.IsMatch(input, RegexHelper.DomainRegex));

‎Source/NETworkManager.Utilities/RegexHelper.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ public static partial class RegexHelper
170170
// Match a hostname with subnetmask like server-01.example.com/255.255.255.0
171171
public const string HostnameOrDomainWithSubnetmaskRegex = $@"^{HostnameOrDomainValues}\/{SubnetmaskValues}$";
172172

173-
// Match a domain local.example.com (labels without nested quantifiers, which backtrack exponentially for an invalid
174-
// input with many labels)
173+
// Match a domain local.example.com: labels like a hostname (see HostnameLabelValues, no hyphen at the start or end)
174+
// and a top-level domain of letters. Without nested quantifiers, which backtrack exponentially for an invalid input
175+
// with many labels.
175176
public const string DomainRegex =
176-
@"^(?=.{1,255}$)[a-zA-Z0-9\-_]{1,63}(\.[a-zA-Z0-9\-_]{1,63})*\.[a-zA-Z]{2,63}\.?$";
177+
$@"^(?=.{{1,255}}$)(?:{HostnameLabelValues}\.)+[a-zA-Z]{{2,63}}\.?$";
177178

178179
// Private port values (1-65535, without leading zeros)
179180
private const string PortValues =

‎Website/docs/changelog/next-release.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Release date: **xx.xx.2026**
194194

195195
**Input validation**
196196

197-
- Fixed host names being accepted with a hyphen at the start or end of a label other than the first (e.g. `server.-bad-.com`) and with only digits (e.g. `10.0.0.` or `192.168.1`, which are an incomplete IPv4 address). IPv4 addresses are still accepted in all host fields, now checked explicitly in the **Remote Desktop** host field. [#3646](https://github.com/BornToBeRoot/NETworkManager/pull/3646)
197+
- Fixed host names being accepted with a hyphen at the start or end of a label other than the first (e.g. `server.-bad-.com`) and with only digits (e.g. `10.0.0.` or `192.168.1`, which are an incomplete IPv4 address). The same applies to the domain in **Whois**. IPv4 addresses are still accepted in all host fields, now checked explicitly in the **Remote Desktop** host field. [#3646](https://github.com/BornToBeRoot/NETworkManager/pull/3646)
198198
- Fixed MAC addresses and their first 3 bytes (**Wake on LAN**, **Lookup** > **OUI**, profiles) being accepted with any character instead of a dot in the format `0000.0000.0000` (e.g. `0011 2233 4455`). [#3646](https://github.com/BornToBeRoot/NETworkManager/pull/3646)
199199
- Fixed IPv6 subnets in the **Subnet Calculator** being accepted with a leading `s` (e.g. `sss2001:db8::/32`) and rejected with an embedded IPv4 address (e.g. `::ffff:192.168.0.1/96`). [#3646](https://github.com/BornToBeRoot/NETworkManager/pull/3646)
200200
- Fixed the port of the **Remote Desktop** host field (`host:port`) being accepted empty or as `0`. [#3646](https://github.com/BornToBeRoot/NETworkManager/pull/3646)

0 commit comments

Comments
 (0)