Skip to content

Commit

Permalink
fix: conda#412
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Nov 23, 2023
1 parent 4fb3490 commit 7a697ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
46 changes: 39 additions & 7 deletions crates/rattler_conda_types/src/channel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use itertools::Itertools;
use std::borrow::Cow;
use std::path::{Component, Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -284,7 +285,20 @@ fn parse_scheme(channel: &str) -> Option<&str> {

/// Returns true if the specified string is considered to be a path
fn is_path(path: &str) -> bool {
lazy_regex::regex!(r"(\./|\.\.|~|/|[a-zA-Z]:[/\\]|\\\\|//)").is_match(path)
// Check if the path starts with a common path prefix
if path.starts_with("./")
|| path.starts_with("..")
|| path.starts_with('~')
|| path.starts_with('/')
|| path.starts_with("\\\\")
|| path.starts_with("//")
{
return true;
}

// A drive letter followed by a colon and a (backward or forward) slash
matches!(path.chars().take(3).collect_tuple(),
Some((letter, ':', '/' | '\\')) if letter.is_alphabetic())
}

/// Normalizes a file path by eliminating `..` and `.`.
Expand Down Expand Up @@ -328,15 +342,14 @@ fn absolute_path(path: &Path) -> Cow<'_, Path> {

#[cfg(test)]
mod tests {
use crate::channel::{absolute_path, normalize_path, parse_platforms};
use crate::{ParseChannelError, ParsePlatformError};
use super::*;
use smallvec::smallvec;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{
path::{Path, PathBuf},
str::FromStr,
};
use url::Url;

use super::{parse_scheme, Channel, ChannelConfig, Platform};

#[test]
fn test_parse_platforms() {
assert_eq!(
Expand Down Expand Up @@ -524,5 +537,24 @@ mod tests {
);
assert_eq!(channel.name.as_deref(), Some("pkgs/main"));
assert_eq!(channel.platforms, Some(smallvec![platform]));

let channel = Channel::from_str("conda-forge/label/rust_dev", &config).unwrap();
assert_eq!(
channel.base_url,
Url::from_str("https://conda.anaconda.org/conda-forge/label/rust_dev/").unwrap()
);
assert_eq!(channel.name.as_deref(), Some("conda-forge/label/rust_dev"));
}

#[test]
fn test_is_path() {
assert!(is_path("./foo"));
assert!(is_path("/foo"));
assert!(is_path("~/foo"));
assert!(is_path("../foo"));
assert!(is_path("/C:/foo"));
assert!(is_path("C:/foo"));

assert!(!is_path("conda-forge/label/rust_dev"));
}
}
3 changes: 1 addition & 2 deletions crates/rattler_package_streaming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! This crate provides the ability to extract a Conda package archive or specific parts of it.
use rattler_digest::{Md5Hash, Sha256Hash};
use rattler_networking::redact_known_secrets_from_error;

pub mod read;
pub mod seek;
Expand Down Expand Up @@ -49,7 +48,7 @@ pub enum ExtractError {
#[cfg(feature = "reqwest")]
impl From<::reqwest::Error> for ExtractError {
fn from(err: ::reqwest::Error) -> Self {
Self::ReqwestError(redact_known_secrets_from_error(err))
Self::ReqwestError(rattler_networking::redact_known_secrets_from_error(err))
}
}

Expand Down

0 comments on commit 7a697ee

Please sign in to comment.