Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block bad words for package names #998

Open
ken-matsui opened this issue Oct 2, 2024 · 0 comments
Open

Block bad words for package names #998

ken-matsui opened this issue Oct 2, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ken-matsui
Copy link
Member

Can we somehow block bad words for package names? We need this feature in the server as well and this can be implemented here:

poac/src/Manifest.cc

Lines 202 to 242 in 6e5cdda

// Returns an error message if the package name is invalid.
std::optional<std::string> // TODO: result-like types make more sense.
validatePackageName(const std::string_view name) noexcept {
// Empty
if (name.empty()) {
return "must not be empty";
}
// Only one character
if (name.size() == 1) {
return "must be more than one character";
}
// Only lowercase letters, numbers, dashes, and underscores
for (const char c : name) {
if (!std::islower(c) && !std::isdigit(c) && c != '-' && c != '_') {
return "must only contain lowercase letters, numbers, dashes, and "
"underscores";
}
}
// Start with a letter
if (!std::isalpha(name[0])) {
return "must start with a letter";
}
// End with a letter or digit
if (!std::isalnum(name[name.size() - 1])) {
return "must end with a letter or digit";
}
// Using C++ keywords
const std::unordered_set<std::string_view> keywords = {
#include "Keywords.def"
};
if (keywords.contains(name)) {
return "must not be a C++ keyword";
}
return std::nullopt;
}

@ken-matsui ken-matsui added the enhancement New feature or request label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant