mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-05-04 10:33:47 +01:00
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:
parent
7fdea814d8
commit
7043f3a499
2 changed files with 23 additions and 0 deletions
|
@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Update `full-moon` dependency to 2.0.0 to support new Luau syntax by @daimond113
|
- 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
|
## [0.6.2] - 2025-03-14
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -172,6 +172,20 @@ impl FromStr for Alias {
|
||||||
return Err(errors::AliasFromStr::Empty);
|
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
|
if !s
|
||||||
.chars()
|
.chars()
|
||||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
||||||
|
@ -286,6 +300,14 @@ pub mod errors {
|
||||||
#[error("the alias is empty")]
|
#[error("the alias is empty")]
|
||||||
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 _
|
/// 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 _")]
|
#[error("alias `{0}` contains characters outside a-z, A-Z, 0-9, -, and _")]
|
||||||
InvalidCharacters(String),
|
InvalidCharacters(String),
|
||||||
|
|
Loading…
Add table
Reference in a new issue