-
Notifications
You must be signed in to change notification settings - Fork 19
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
Reserved word check should be post canonical conversion #2161
Conversation
@@ -35,7 +35,7 @@ pub fn convert_to_canonical(input_str: &str) -> alloc::string::String { | |||
let white_space_stripped = strip_unicode_whitespace(input_str); | |||
let diacriticals_stripped = strip_diacriticals(&white_space_stripped); | |||
let confusables_removed = replace_confusables(&diacriticals_stripped); | |||
confusables_removed.to_ascii_lowercase() | |||
confusables_removed.to_lowercase() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we didn't use this before, but we should have.
)?; | ||
|
||
Self::validate_canonical_handle_length(&canonical_handle_str)?; | ||
Self::validate_canonical_handle(&canonical_handle_str)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having more than one of these was nice, but getting confusing as we now had 3 checks to make on canonical handles
@@ -668,33 +664,36 @@ pub mod pallet { | |||
Error::<T>::InvalidHandleCharacterLength | |||
); | |||
|
|||
ensure!(!is_reserved_handle(&base_handle_str), Error::<T>::HandleIsNotAllowed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer a check done on the base_handle pre-canonicalization
&canonical_handle_str, | ||
) | ||
.is_ok(); | ||
return Self::validate_canonical_handle(&canonical_handle_str).is_ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this wasn't doing all the other canonical checks, but it should have been.
Codecov ReportAttention: Patch coverage is
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Read through changes
lgtm
|
||
// We MUST have the RESERVED_WORDS constant as canonical. | ||
// Cannot easily be canonicalized at compile time currently | ||
#[test] | ||
fn ensure_reserved_words_canonical() { | ||
for &word in &RESERVED_WORDS { | ||
let canonical = crate::convert_to_canonical(word); | ||
assert_eq!( | ||
word, canonical, | ||
"The reserved word '{}' MUST match canonical form: '{}'", | ||
word, canonical | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this would be a better test or not; otherwise technically the test passes if even if convert_to_canonical
is a no-op
// We MUST have the RESERVED_WORDS constant as canonical. | |
// Cannot easily be canonicalized at compile time currently | |
#[test] | |
fn ensure_reserved_words_canonical() { | |
for &word in &RESERVED_WORDS { | |
let canonical = crate::convert_to_canonical(word); | |
assert_eq!( | |
word, canonical, | |
"The reserved word '{}' MUST match canonical form: '{}'", | |
word, canonical | |
); | |
} | |
} | |
// We MUST have the RESERVED_WORDS constant as canonical. | |
// Cannot easily be canonicalized at compile time currently | |
#[test] | |
fn ensure_reserved_words_canonical() { | |
const TEST_WORDS: [&str; 8] = | |
["admin", "everyone", "all", "administrator", "mod", "moderator", "here", "channel"]; | |
for (i, &word) in TEST_WORDS.iter().enumerate() { | |
let canonical = crate::convert_to_canonical(word); | |
assert_eq!( | |
RESERVED_WORDS[i], canonical, | |
"The reserved word '{}' MUST match canonical form: '{}'", | |
word, canonical | |
); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. This is just a check to make sure that convert_to_canonical
does NOT change the output of RESERVED_WORDS
. Other test (`test_is_reserved_canonical_handle_happy_path) make sure that reserved words are rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read the code. Looked good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Goal
The goal of this PR is to make sure that reserved words cannot be used in different forms.
Closes #2147
Discussion
to_lowercase
instead ofto_ascii_lowercase
for better handlingChecklist