mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
os/hostname: fix mac address handling when last section starts with '0'
I hit an edge case when using Private Wi-Fi addressing on macOS where the last section of the randomized mac address starts with a '0'. The hostname parsing for the shell integration didn't handle this case, so issue #2512 reappeared. This fixes that by explicitly handling port numbers < 10.
This commit is contained in:
@ -36,15 +36,16 @@ pub fn bufPrintHostnameFromFileUri(
|
|||||||
// it's not a partial MAC-address.
|
// it's not a partial MAC-address.
|
||||||
const port = uri.port orelse return host;
|
const port = uri.port orelse return host;
|
||||||
|
|
||||||
// If the port is not a 2-digit number we're not looking at a partial
|
// If the port is not a 1 or 2-digit number we're not looking at a partial
|
||||||
// MAC-address, and instead just a regular port so we return the plain
|
// MAC-address, and instead just a regular port so we return the plain
|
||||||
// URI hostname.
|
// URI hostname.
|
||||||
if (port < 10 or port > 99) return host;
|
if (port > 99) return host;
|
||||||
|
|
||||||
var fbs = std.io.fixedBufferStream(buf);
|
var fbs = std.io.fixedBufferStream(buf);
|
||||||
try std.fmt.format(
|
try std.fmt.format(
|
||||||
fbs.writer(),
|
fbs.writer(),
|
||||||
"{s}:{d}",
|
// Make sure "port" is always 2 digits, prefixed with a 0 when "port" is a 1-digit number.
|
||||||
|
"{s}:{d:0>2}",
|
||||||
.{ host, port },
|
.{ host, port },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -85,6 +86,14 @@ test "bufPrintHostnameFromFileUri succeeds with hostname as mac address" {
|
|||||||
try std.testing.expectEqualStrings("12:34:56:78:90:12", actual);
|
try std.testing.expectEqualStrings("12:34:56:78:90:12", actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "bufPrintHostnameFromFileUri succeeds with hostname as a mac address and the last section is < 10" {
|
||||||
|
const uri = try std.Uri.parse("file://12:34:56:78:90:05");
|
||||||
|
|
||||||
|
var buf: [posix.HOST_NAME_MAX]u8 = undefined;
|
||||||
|
const actual = try bufPrintHostnameFromFileUri(&buf, uri);
|
||||||
|
try std.testing.expectEqualStrings("12:34:56:78:90:05", actual);
|
||||||
|
}
|
||||||
|
|
||||||
test "bufPrintHostnameFromFileUri returns only hostname when there is a port component in the URI" {
|
test "bufPrintHostnameFromFileUri returns only hostname when there is a port component in the URI" {
|
||||||
// First: try with a non-2-digit port, to test general port handling.
|
// First: try with a non-2-digit port, to test general port handling.
|
||||||
const four_port_uri = try std.Uri.parse("file://has-a-port:1234");
|
const four_port_uri = try std.Uri.parse("file://has-a-port:1234");
|
||||||
|
Reference in New Issue
Block a user