Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

## Other

- Replace `path_abs` dependency with `std::path::absolute` (stable since Rust 1.79), see #3622 (@Xavrir)
- Bump MSRV to 1.88, update `time` crate to 0.3.47 to fix RUSTSEC-2026-0009, see #3581 (@NORMAL-EX)

## Syntaxes
Expand Down
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ serde = "1.0"
serde_derive = "1.0"
serde_yaml = "0.9.28"
semver = "1.0"
path_abs = { version = "0.5", default-features = false }
clircle = { version = "0.6.1", default-features = false }
bugreport = { version = "0.5.0", optional = true }
etcetera = { version = "0.11.0", optional = true }
Expand Down
43 changes: 36 additions & 7 deletions src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::ffi::OsStr;
use std::fs;
use std::path::Path;
use std::path::{self, Component, Path, PathBuf};

use once_cell::unsync::OnceCell;

use syntect::highlighting::Theme;
use syntect::parsing::{SyntaxReference, SyntaxSet};

use path_abs::PathAbs;

use crate::error::*;
use crate::input::{InputReader, OpenedInput};
use crate::syntax_mapping::ignored_suffixes::IgnoredSuffixes;
Expand All @@ -29,6 +27,40 @@ mod build_assets;
mod lazy_theme_set;
mod serialized_syntax_set;

fn absolute_normalized(path: &Path) -> PathBuf {
let absolute = match path::absolute(path) {
Ok(p) => p,
Err(_) => return path.to_owned(),
};
let mut normalized = PathBuf::new();
for component in absolute.components() {
match component {
Component::ParentDir => {
normalized.pop();
}
Component::CurDir => {}
_ => normalized.push(component),
}
}
strip_windows_verbatim_prefix(normalized)
}

/// On Windows, strip the extended-length `\\?\` prefix from paths so they
/// match glob patterns built from environment variables (which are also
/// stripped in `builtin.rs`).
#[cfg(windows)]
fn strip_windows_verbatim_prefix(path: PathBuf) -> PathBuf {
path.to_str()
.and_then(|s| s.strip_prefix(r"\\?\"))
.map(PathBuf::from)
.unwrap_or(path)
}

#[cfg(not(windows))]
fn strip_windows_verbatim_prefix(path: PathBuf) -> PathBuf {
path
}

#[derive(Debug)]
pub struct HighlightingAssets {
syntax_set_cell: OnceCell<SyntaxSet>,
Expand Down Expand Up @@ -224,10 +256,7 @@ impl HighlightingAssets {

let path = input.path();
let path_syntax = if let Some(path) = path {
self.get_syntax_for_path(
PathAbs::new(path).map_or_else(|_| path.to_owned(), |p| p.as_path().to_path_buf()),
mapping,
)
self.get_syntax_for_path(absolute_normalized(path), mapping)
} else {
Err(Error::UndetectedSyntax("[unknown]".into()))
};
Expand Down
17 changes: 16 additions & 1 deletion src/syntax_mapping/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn build_matcher_dynamic(segs: &[MatcherSegment]) -> Option<GlobMatcher> {
MatcherSegment::Text(s) => buf.push_str(s),
MatcherSegment::Env(var) => {
let replaced = env::var(var).ok()?;
buf.push_str(&replaced);
buf.push_str(&strip_verbatim_prefix(&replaced));
}
}
}
Expand All @@ -81,6 +81,21 @@ fn build_matcher_dynamic(segs: &[MatcherSegment]) -> Option<GlobMatcher> {
Some(matcher)
}

/// On Windows, environment variables (e.g. `XDG_CONFIG_HOME`, `HOME`) may
/// contain paths with the extended-length `\\?\` prefix if they were set from
/// a canonicalized path. Since `std::path::absolute` does NOT produce this
/// prefix, we strip it from env var values so that glob patterns and file
/// paths use a consistent representation.
#[cfg(windows)]
fn strip_verbatim_prefix(s: &str) -> String {
s.strip_prefix(r"\\?\").unwrap_or(s).to_string()
}

#[cfg(not(windows))]
fn strip_verbatim_prefix(s: &str) -> String {
s.to_string()
}

/// A segment of a dynamic builtin matcher.
///
/// Used internally by `Lazy<Option<GlobMatcher>>`'s lazy evaluation closure.
Expand Down