refactor: impose additional limits on aliases

Aliases didn't have a maximum length before, and
they could've been made with reserved Windows file
names which could've caused issues. This commit
imposes a limit of 24 characters on aliases and
forbids the reserved file names.
This commit is contained in:
daimond113 2025-04-30 22:05:28 +02:00
parent 7fdea814d8
commit 7043f3a499
No known key found for this signature in database
GPG key ID: 640DC95EC1190354
2 changed files with 23 additions and 0 deletions

View file

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Update `full-moon` dependency to 2.0.0 to support new Luau syntax by @daimond113
- Limit aliases to 24 characters & forbid reserved Windows file names by @daimond113
## [0.6.2] - 2025-03-14
### Fixed

View file

@ -172,6 +172,20 @@ impl FromStr for Alias {
return Err(errors::AliasFromStr::Empty);
}
if s.len() > 24 {
return Err(errors::AliasFromStr::TooLong(s.to_string()));
}
if [
"con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", "com5", "com6", "com7",
"com8", "com9", "com¹", "com²", "com³", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6",
"lpt7", "lpt8", "lpt9", "lpt¹", "lpt²", "lpt³",
]
.contains(&s.to_ascii_lowercase().as_str())
{
return Err(errors::AliasFromStr::Reserved(s.to_string()));
}
if !s
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
@ -286,6 +300,14 @@ pub mod errors {
#[error("the alias is empty")]
Empty,
/// The alias has more than 24 characters
#[error("alias `{0}` has more than 24 characters")]
TooLong(String),
/// The alias is a reserved file name
#[error("alias `{0}` is a reserved file name")]
Reserved(String),
/// The alias contains characters outside a-z, A-Z, 0-9, -, and _
#[error("alias `{0}` contains characters outside a-z, A-Z, 0-9, -, and _")]
InvalidCharacters(String),