Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #412 #413

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 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,24 @@ 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)
if path.contains("://") {
return false;
}

// 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 +346,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 +541,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