mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +03:00
Adjust packaging/https to check for misleading unicode characters
Related to #5487
This commit is contained in:
parent
8cbd40a743
commit
842f8b9941
@ -29,6 +29,14 @@ pub struct PackageMetadata<'a> {
|
||||
/// - .tar.br
|
||||
const VALID_EXTENSION_SUFFIXES: [&str; 2] = [".gz", ".br"];
|
||||
|
||||
/// Characters that could be misleading if present in URLs:
|
||||
///
|
||||
/// ⁄ - U+2044 Fraction Slash
|
||||
/// ∕ - U+2215 Division Slash
|
||||
/// / - U+FF0F Fullwidth Solidus
|
||||
/// ⧸ - U+29F8 Big Solidus
|
||||
const MISLEADING_CHARACTERS_IN_URL: [&str; 4] = ["\u{2044}", "\u{2215}", "\u{FF0F}", "\u{29F8}"];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UrlProblem {
|
||||
InvalidExtensionSuffix(String),
|
||||
@ -36,6 +44,7 @@ pub enum UrlProblem {
|
||||
InvalidFragment(String),
|
||||
MissingHash,
|
||||
MissingHttps,
|
||||
MisleadingCharacter,
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for PackageMetadata<'a> {
|
||||
@ -56,6 +65,13 @@ impl<'a> PackageMetadata<'a> {
|
||||
}
|
||||
};
|
||||
|
||||
// Next, check if there are misleading characters in the URL
|
||||
for misleading_character in MISLEADING_CHARACTERS_IN_URL {
|
||||
if url.contains(misleading_character) {
|
||||
return Err(UrlProblem::MisleadingCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
// Next, get the (optional) URL fragment, which must be a .roc filename
|
||||
let (without_fragment, fragment) = match without_protocol.rsplit_once('#') {
|
||||
Some((before_fragment, fragment)) => {
|
||||
|
Loading…
Reference in New Issue
Block a user