aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/os/hostname.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/os/hostname.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/os/hostname.zig')
-rw-r--r--vendor/libghostty-vt/src/os/hostname.zig90
1 files changed, 3 insertions, 87 deletions
diff --git a/vendor/libghostty-vt/src/os/hostname.zig b/vendor/libghostty-vt/src/os/hostname.zig
index af9148fb..969b4baa 100644
--- a/vendor/libghostty-vt/src/os/hostname.zig
+++ b/vendor/libghostty-vt/src/os/hostname.zig
@@ -7,91 +7,6 @@ pub const LocalHostnameValidationError = error{
Unexpected,
};
-/// Validates a hostname according to [RFC 1123](https://www.rfc-editor.org/rfc/rfc1123)
-///
-/// std.net.isValidHostname is (currently) too generous. It considers strings like
-/// ".example.com", "exa..mple.com", and "-example.com" to be valid hostnames, which
-/// is incorrect.
-pub fn isValid(hostname: []const u8) bool {
- if (hostname.len == 0) return false;
- if (hostname[0] == '.') return false;
-
- // Ignore trailing dot (FQDN). It doesn't count toward our length.
- const end = if (hostname[hostname.len - 1] == '.') end: {
- if (hostname.len == 1) return false;
- break :end hostname.len - 1;
- } else hostname.len;
-
- if (end > 253) return false;
-
- // Hostnames are divided into dot-separated "labels", which:
- //
- // - Start with a letter or digit
- // - Can contain letters, digits, or hyphens
- // - Must end with a letter or digit
- // - Have a minimum of 1 character and a maximum of 63
- var label_start: usize = 0;
- var label_len: usize = 0;
- for (hostname[0..end], 0..) |c, i| {
- switch (c) {
- '.' => {
- if (label_len == 0 or label_len > 63) return false;
- if (!std.ascii.isAlphanumeric(hostname[label_start])) return false;
- if (!std.ascii.isAlphanumeric(hostname[i - 1])) return false;
-
- label_start = i + 1;
- label_len = 0;
- },
- '-' => {
- label_len += 1;
- },
- else => {
- if (!std.ascii.isAlphanumeric(c)) return false;
- label_len += 1;
- },
- }
- }
-
- // Validate the final label
- if (label_len == 0 or label_len > 63) return false;
- if (!std.ascii.isAlphanumeric(hostname[label_start])) return false;
- if (!std.ascii.isAlphanumeric(hostname[end - 1])) return false;
-
- return true;
-}
-
-test isValid {
- const testing = std.testing;
-
- // Valid hostnames
- try testing.expect(isValid("example"));
- try testing.expect(isValid("example.com"));
- try testing.expect(isValid("www.example.com"));
- try testing.expect(isValid("sub.domain.example.com"));
- try testing.expect(isValid("example.com."));
- try testing.expect(isValid("host-name.example.com."));
- try testing.expect(isValid("123.example.com."));
- try testing.expect(isValid("a-b.com"));
- try testing.expect(isValid("a.b.c.d.e.f.g"));
- try testing.expect(isValid("127.0.0.1")); // Also a valid hostname
- try testing.expect(isValid("a" ** 63 ++ ".com")); // Label exactly 63 chars (valid)
- try testing.expect(isValid("a." ** 126 ++ "a")); // Total length 253 (valid)
-
- // Invalid hostnames
- try testing.expect(!isValid(""));
- try testing.expect(!isValid(".example.com"));
- try testing.expect(!isValid("example.com.."));
- try testing.expect(!isValid("host..domain"));
- try testing.expect(!isValid("-hostname"));
- try testing.expect(!isValid("hostname-"));
- try testing.expect(!isValid("a.-.b"));
- try testing.expect(!isValid("host_name.com"));
- try testing.expect(!isValid("."));
- try testing.expect(!isValid(".."));
- try testing.expect(!isValid("a" ** 64 ++ ".com")); // Label length 64 (too long)
- try testing.expect(!isValid("a." ** 126 ++ "ab")); // Total length 254 (too long)
-}
-
/// Checks if a hostname is local to the current machine. This matches
/// both "localhost" and the current hostname of the machine (as returned
/// by `gethostname`).
@@ -105,7 +20,7 @@ pub fn isLocal(hostname: []const u8) LocalHostnameValidationError!bool {
const windows = @import("windows.zig");
var buf: [256:0]u8 = undefined;
var nSize: windows.DWORD = buf.len;
- if (windows.exp.kernel32.GetComputerNameA(&buf, &nSize) == 0) return false;
+ if (windows.exp.kernel32.GetComputerNameA(&buf, &nSize) == windows.FALSE) return false;
const ourHostname = buf[0..nSize];
return std.mem.eql(u8, hostname, ourHostname);
},
@@ -127,7 +42,8 @@ test "isLocal returns true when hostname is local" {
const windows = @import("windows.zig");
var buf: [256:0]u8 = undefined;
var nSize: windows.DWORD = buf.len;
- if (windows.exp.kernel32.GetComputerNameA(&buf, &nSize) == 0) return error.GetComputerNameFailed;
+ if (windows.exp.kernel32.GetComputerNameA(&buf, &nSize) == windows.FALSE)
+ return error.GetComputerNameFailed;
const localHostname = buf[0..nSize];
try std.testing.expect(try isLocal(localHostname));
},