Skip to content

Commit

Permalink
fix: update UUID validation (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekyEggo authored Feb 16, 2024
1 parent 1dd670b commit bf93bb4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function promptForPluginInfo(): Promise<PluginInfo> {
default: ({ author, name }: PluginInfo): string | undefined => generatePluginId(author, name),
validate: (uuid: string): boolean | string => {
if (!isValidPluginId(uuid)) {
return "UUID must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), underscores (_), and periods (.).";
return "UUID must be in reverse DNS format, and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.).";
}

if (getPlugins().some((p) => p.uuid === uuid)) {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export const link = command<LinkOptions>(
return feedback
.error("Linking failed")
.log(`Invalid directory name: ${basename(options.path)}`)
.log(
'Name should represent a reverse DNS format and have a suffix of ".sdPlugin". Name must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), underscores (_), and periods (.).'
)
.log('Name must be in reverse DNS format, be suffixed with ".sdPlugin", and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.).')
.log(`Examples: ${chalk.green("com.elgato.wave-link.sdPlugin")}, ${chalk.green("tv.twitch.studio.sdPlugin")}`)
.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/stream-deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function isValidPluginId(uuid: string | undefined): boolean {
return false;
}

return /^([a-z0-9\-_]*[a-z0-9][a-z0-9\-_]*\.){2}[a-z0-9\-_]*[a-z0-9][a-z0-9\-_]*$/.test(uuid);
return /^([a-z0-9-]+)(\.[a-z0-9-]+)+$/.test(uuid);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/validation/plugin/rules/path-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const pathIsDirectoryAndUuid = rule<PluginContext>(function (plugin: Plug
}

if (!isValidPluginId(plugin.uuid)) {
this.addError(this.path, "Name must be a valid UUID in reverse DNS format", {
suggestion: "UUIDs must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), underscores (_), and periods (.), for example 'com.elgato.wave-link'"
this.addError(this.path, "Name must be in reverse DNS format, and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.)", {
suggestion: "Example: 'com.elgato.wave-link'"
});
}
});

0 comments on commit bf93bb4

Please sign in to comment.