Skip to content

Commit dc8216c

Browse files
authored
feat: allow dashes and ensure that first char in name is ascii alphabetic (#73)
* feat: allow dashes and ensure that first char in name is ascii alphabetic * fix: allow dashes in test * fix: test dash at front
1 parent 61b4fb6 commit dc8216c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

contracts/registry/src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ pub enum Error {
2727
/// New version must be greater than the most recent version
2828
VersionMustBeGreaterThanCurrent = 11,
2929
/// Invalid name.
30-
/// Must be 64 characters or less; ascii alphanumeric or '_'; start with a letter; and not be a Rust keyword
30+
/// Must be 64 characters or less;
31+
/// ascii alphanumeric, '-', or '_';
32+
/// start with a ascii alphabetic character;
33+
/// and not be a Rust keyword
3134
InvalidName = 12,
3235
/// Invalid Version. Must be valid cargo version
3336
InvalidVersion = 13,

contracts/registry/src/name.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ pub(crate) fn is_valid(s: &String) -> bool {
1212
let Ok(s) = core::str::from_utf8(first) else {
1313
return false;
1414
};
15-
if is_keyword(s) || s.starts_with(|c: char| c == '_' || c.is_numeric()) {
15+
if is_keyword(s) || !s.starts_with(|c: char| c.is_ascii_alphabetic()) {
1616
return false;
1717
}
18-
s.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
18+
s.chars()
19+
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
1920
}
2021

2122
pub(crate) fn validate(s: &String) -> Result<(), Error> {

contracts/registry/src/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ fn validate_names() {
125125
"abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgha",
126126
false,
127127
);
128-
test_string("a-a_b", false);
128+
test_string("a-a_b", true);
129+
test_string("a-a]]]_b", false);
129130
test_string("_ab", false);
131+
test_string("-ab", false);
130132
test_string("1ab", false);
131133
}
132134

0 commit comments

Comments
 (0)