From 0970597d215eef59517f0bf5bea9c7ecd536fd21 Mon Sep 17 00:00:00 2001 From: Sergey Rubanov Date: Mon, 18 Sep 2023 16:01:09 +0200 Subject: [PATCH] feat(src/cli/cli.cc): check if Bundle ID is in reverse DNS notation --- api/config.md | 2 +- src/cli/cli.cc | 16 +++++++++++++--- src/cli/templates.hh | 4 +++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/api/config.md b/api/config.md index 96fd2c5321..0186439dfa 100644 --- a/api/config.md +++ b/api/config.md @@ -67,7 +67,7 @@ flags | | Advanced Compiler Settings for debug purposes (ie C++ compiler -g, e Key | Default Value | Description :--- | :--- | :--- -bundle_identifier | | A unique ID that identifies the bundle (used by all app stores). It's required when `[meta] type` is not `"extension"`. +bundle_identifier | | A unique ID that identifies the bundle (used by all app stores). It's required when `[meta] type` is not `"extension"`. It should be in a reverse DNS notation https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier#discussion copyright | | A string that gets used in the about dialog and package meta info. description | | A short description of the app. file_limit | | Set the limit of files that can be opened by your process. diff --git a/src/cli/cli.cc b/src/cli/cli.cc index 0dcd49c647..f131fc42d5 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -2413,9 +2413,19 @@ int main (const int argc, const char* argv[]) { createSubcommand("build", buildOptions, true, [&](Map optionsWithValue, std::unordered_set optionsWithoutValue) -> void { auto isForExtensionOnly = settings["meta_type"] == "extension" || settings["build_type"] == "extension"; - if (settings["meta_bundle_identifier"].size() == 0 !isForExtensionOnly) { - log("ERROR: [meta] bundle_identifier option is empty"); - exit(1); + if (!isForExtensionOnly) { + if (settings["meta_bundle_identifier"].size() == 0) { + log("ERROR: [meta] bundle_identifier option is empty"); + exit(1); + } + + std::regex reverseDnsPattern(R"(^[a-z0-9]+([-a-z0-9]*[a-z0-9]+)?(\.[a-z0-9]+([-a-z0-9]*[a-z0-9]+)?)*$)", std::regex::icase); + if (!std::regex_match(settings["meta_bundle_identifier"], reverseDnsPattern)) { + log("ERROR: [meta] bundle_name has invalid format :" + settings["meta_bundle_identifier"]); + log("Please use reverse DNS notation (https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier#discussion)"); + exit(1); + } + } String argvForward = ""; diff --git a/src/cli/templates.hh b/src/cli/templates.hh index 7aa988e1b7..9d40c0f7c7 100644 --- a/src/cli/templates.hh +++ b/src/cli/templates.hh @@ -1429,7 +1429,9 @@ flags = "-g" [meta] -; A unique ID that identifies the bundle (used by all app stores). It's required when `[meta] type` is not `"extension"`. +; A unique ID that identifies the bundle (used by all app stores). +; It's required when `[meta] type` is not `"extension"`. +; It should be in a reverse DNS notation https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier#discussion bundle_identifier = "com.beepboop" ; A string that gets used in the about dialog and package meta info.