Skip to content
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
16 changes: 8 additions & 8 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// file that was distributed with this source code.
use super::PathData;
use lscolors::{Indicator, LsColors, Style};
use rustc_hash::FxHashMap;
use std::borrow::Cow;
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fs::{self, Metadata};
Expand Down Expand Up @@ -45,7 +45,7 @@ pub(crate) struct StyleManager<'a> {
pub(crate) initial_reset_is_done: bool,
pub(crate) colors: &'a LsColors,
/// raw indicator codes as specified in LS_COLORS (if available)
indicator_codes: HashMap<Indicator, String>,
indicator_codes: FxHashMap<Indicator, String>,
/// whether ln=target is active
ln_color_from_target: bool,
}
Expand Down Expand Up @@ -746,8 +746,8 @@ fn is_valid_ls_colors_prefix(label: [u8; 2]) -> bool {
)
}

fn parse_indicator_codes() -> (HashMap<Indicator, String>, bool) {
let mut indicator_codes = HashMap::new();
fn parse_indicator_codes() -> (FxHashMap<Indicator, String>, bool) {
let mut indicator_codes = FxHashMap::default();
let mut ln_color_from_target = false;

// LS_COLORS validity is checked before enabling color output, so parse
Expand Down Expand Up @@ -813,7 +813,7 @@ mod tests {

fn style_manager(
colors: &LsColors,
indicator_codes: HashMap<Indicator, String>,
indicator_codes: FxHashMap<Indicator, String>,
) -> StyleManager<'_> {
StyleManager {
current_style: None,
Expand All @@ -827,21 +827,21 @@ mod tests {
#[test]
fn has_indicator_style_ignores_fallback_styles() {
let colors = LsColors::from_string("ex=00:fi=32");
let manager = style_manager(&colors, HashMap::new());
let manager = style_manager(&colors, FxHashMap::default());
assert!(!manager.has_indicator_style(Indicator::ExecutableFile));
}

#[test]
fn has_indicator_style_detects_explicit_styles() {
let colors = LsColors::from_string("ex=01;32");
let manager = style_manager(&colors, HashMap::new());
let manager = style_manager(&colors, FxHashMap::default());
assert!(manager.has_indicator_style(Indicator::ExecutableFile));
}

#[test]
fn has_indicator_style_detects_raw_codes() {
let colors = LsColors::empty();
let mut indicator_codes = HashMap::new();
let mut indicator_codes = FxHashMap::default();
indicator_codes.insert(Indicator::Directory, "01;34".to_string());
let manager = style_manager(&colors, indicator_codes);
assert!(manager.has_indicator_style(Indicator::Directory));
Expand Down
6 changes: 3 additions & 3 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3527,11 +3527,11 @@ fn create_hyperlink(name: &OsStr, path: &PathData) -> OsString {
// Get bytes for URL encoding in a cross-platform way
let absolute_path_bytes = os_str_as_bytes_lossy(absolute_path.as_os_str());

// Create a set of safe ASCII bytes that don't need encoding
// a set of safe ASCII bytes that don't need encoding
#[cfg(not(target_os = "windows"))]
let unencoded_bytes: std::collections::HashSet<u8> = "_-.~/".bytes().collect();
let unencoded_bytes = b"_-.~/";
#[cfg(target_os = "windows")]
let unencoded_bytes: std::collections::HashSet<u8> = "_-.~/\\:".bytes().collect();
let unencoded_bytes = b"_-.~/\\:";

// Encode at byte level to properly handle UTF-8 sequences and preserve invalid UTF-8
let full_encoded_path: String = absolute_path_bytes
Expand Down
Loading