diff --git a/CHANGELOG.md b/CHANGELOG.md index 1252037..c82e099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 9105de8..27ab7e0 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -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),