gtk: use 'gio.Application.idIsValid' instead of 'isValidAppId'

pull/7442/head
alex-huff 2025-05-25 13:20:29 -05:00
parent 0415a65083
commit 113c196078
1 changed files with 1 additions and 33 deletions

View File

@ -288,7 +288,7 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
// can develop Ghostty in Ghostty.
const app_id: [:0]const u8 = app_id: {
if (config.class) |class| {
if (isValidAppId(class)) {
if (gio.Application.idIsValid(class) != 0) {
break :app_id class;
} else {
log.warn("invalid 'class' in config, ignoring", .{});
@ -1688,35 +1688,3 @@ fn initActions(self: *App) void {
action_map.addAction(action.as(gio.Action));
}
}
fn isValidAppId(app_id: [:0]const u8) bool {
if (app_id.len > 255) return false;
var hasSep = false;
var lastWasSep = true;
for (app_id) |char| {
switch (char) {
'a'...'z', 'A'...'Z', '_', '-' => {},
'0'...'9', '.' => if (lastWasSep) return false,
else => return false,
}
lastWasSep = char == '.';
hasSep = hasSep or lastWasSep;
}
return hasSep and !lastWasSep;
}
test "isValidAppId" {
try testing.expect(isValidAppId("foo.bar"));
try testing.expect(isValidAppId("foo.bar.baz"));
try testing.expect(isValidAppId("f00.bar"));
try testing.expect(isValidAppId("foo-bar._baz"));
try testing.expect(!isValidAppId("foo"));
try testing.expect(!isValidAppId("foo.bar?"));
try testing.expect(!isValidAppId("foo."));
try testing.expect(!isValidAppId(".foo"));
try testing.expect(!isValidAppId(""));
try testing.expect(!isValidAppId("foo" ** 86));
try testing.expect(!isValidAppId("foo..bar"));
try testing.expect(!isValidAppId("0foo.bar"));
}