mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
gtk: improve app id validation (#7442)
'g_application_id_is_valid' doesn't allow empty elements or elements that start with digits. This commit updates 'isValidAppId' to be more consistant with 'g_application_id_is_valid' avoiding the app id defaulting to 'GTK Application' for app ids like '0foo.bar' or 'foo..bar'.
This commit is contained in:
@ -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,32 +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 or app_id.len == 0) return false;
|
||||
if (app_id[0] == '.') return false;
|
||||
if (app_id[app_id.len - 1] == '.') return false;
|
||||
|
||||
var hasDot = false;
|
||||
for (app_id) |char| {
|
||||
switch (char) {
|
||||
'a'...'z', 'A'...'Z', '0'...'9', '_', '-' => {},
|
||||
'.' => hasDot = true,
|
||||
else => return false,
|
||||
}
|
||||
}
|
||||
if (!hasDot) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
test "isValidAppId" {
|
||||
try testing.expect(isValidAppId("foo.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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user