add comptime check for platform

we only need the mac-address-as-hostname workaround on macos, so we
now have a comptime check to see if we're on macos.
pull/7029/head
Kristófer R 2025-05-13 23:29:46 -04:00
parent 68f48b9911
commit 7760389ab8
No known key found for this signature in database
1 changed files with 5 additions and 0 deletions

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const posix = std.posix; const posix = std.posix;
pub const HostnameParsingError = error{ pub const HostnameParsingError = error{
@ -40,6 +41,10 @@ fn isValidMacAddress(mac_address: []const u8) bool {
/// correctly. /// correctly.
pub fn parseUrl(url: []const u8) !std.Uri { pub fn parseUrl(url: []const u8) !std.Uri {
return std.Uri.parse(url) catch |e| { return std.Uri.parse(url) catch |e| {
// The mac-address-as-hostname issue is specific to macOS so we just return an error if we
// hit it on other platforms.
comptime if (builtin.os.tag != .macos) return e;
// It's possible this is a mac address on macOS where the last 2 characters in the // It's possible this is a mac address on macOS where the last 2 characters in the
// address are non-digits, e.g. 'ff', and thus an invalid port. // address are non-digits, e.g. 'ff', and thus an invalid port.
// //