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(windows): check USERPROFILE env var for finding home directory #24384

Merged
merged 1 commit into from
Jul 1, 2024
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
fix(windows): check USERPROFILE env var for finding home directory
  • Loading branch information
dsherret committed Jul 1, 2024
commit b678fddd331d8e634acc052b0739a8639a644da8
6 changes: 6 additions & 0 deletions cli/cache/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 266,12 @@ pub mod dirs {
}

pub fn home_dir() -> Option<PathBuf> {
if let Some(userprofile) = std::env::var_os("USERPROFILE") {
if !userprofile.is_empty() {
return Some(PathBuf::from(userprofile));
}
}

known_folder(&knownfolders::FOLDERID_Profile)
}
}
4 changes: 2 additions & 2 deletions tests/specs/npm/npmrc_homedir/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -1,9 1,9 @@
{
"if": "unix",
"tempDir": true,
"envs": {
"DENO_FUTURE": "1",
"HOME": "$PWD/../"
"HOME": "$PWD/../",
"USERPROFILE": "$PWD\\..\\"
},
"cwd": "subdir",
"args": "install",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
{
"envs": {
"DENO_FUTURE": "1"
"DENO_FUTURE": "1",
"USERPROFILE": "$DENO_DIR"
},
"tempDir": true,
"args": "install -A -L debug",
Expand Down
19 changes: 11 additions & 8 deletions tests/util/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,24 750,26 @@ pub fn wildcard_match_detailed(
}
None => {
let was_wildcard_or_line = was_last_wildcard || was_last_wildline;
let mut max_found_index = 0;
let mut max_search_text_found_index = 0;
let mut max_current_text_found_index = 0;
for (index, _) in search_text.char_indices() {
let sub_string = &search_text[..index];
if let Some(found_index) = current_text.find(sub_string) {
if was_wildcard_or_line || found_index == 0 {
max_found_index = index;
max_search_text_found_index = index;
max_current_text_found_index = found_index;
} else {
break;
}
} else {
break;
}
}
if !was_wildcard_or_line && max_found_index > 0 {
if !was_wildcard_or_line && max_search_text_found_index > 0 {
output_lines.push(format!(
"<FOUND>{}</FOUND>",
colors::gray(annotate_whitespace(
&search_text[..max_found_index]
&search_text[..max_search_text_found_index]
))
));
}
Expand All @@ -777,18 779,19 @@ pub fn wildcard_match_detailed(
if was_wildcard_or_line {
search_text
} else {
&search_text[max_found_index..]
&search_text[max_search_text_found_index..]
},
)));
if was_wildcard_or_line && max_found_index > 0 {
if was_wildcard_or_line && max_search_text_found_index > 0 {
output_lines.push(format!(
"==== MAX FOUND ====\n{}",
colors::red(annotate_whitespace(
&search_text[..max_found_index]
&search_text[..max_search_text_found_index]
))
));
}
let actual_next_text = &current_text[max_found_index..];
let actual_next_text =
&current_text[max_current_text_found_index..];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was using the incorrect position when there was a wildcard.

let max_next_text_len = 40;
let next_text_len =
std::cmp::min(max_next_text_len, actual_next_text.len());
Expand Down