Skip to content

Allow apostrophe in venv name#8984

Merged
konstin merged 1 commit intomainfrom
konsti/venv-apostrophe
Nov 15, 2024
Merged

Allow apostrophe in venv name#8984
konstin merged 1 commit intomainfrom
konsti/venv-apostrophe

Conversation

@konstin
Copy link
Copy Markdown
Member

@konstin konstin commented Nov 10, 2024

Escape an apostrophe in the venv path name.

Fixes #8947

@konstin konstin added the bug Something isn't working label Nov 10, 2024
@konstin konstin force-pushed the konsti/venv-apostrophe branch from 37a4cad to af574ac Compare November 10, 2024 12:57
@samypr100
Copy link
Copy Markdown
Collaborator

CC @paveldikov for visiblity on the relocatable side

// Bash has `$'\''`, but that's not universal enough.
// We can use implicit string concatenations, by putting the single quote into double
// quotes:
.replace('\'', r#"'"'"'"#)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is implemented somewhere in the codebase already... IIRC it was cited as a shlex.quote() analogue?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, it's in another crate

fn shlex_posix(executable: impl AsRef<Path>) -> String {
// Convert to a display path.
let executable = executable.as_ref().portable_display().to_string();
// Like Python's `shlex.quote`:
// > Use single quotes, and put single quotes into double quotes
// > The string $'b is then quoted as '$'"'"'b'
if executable.contains(' ') {
format!("'{}'", executable.replace('\'', r#"'"'"'"#))
} else {
executable
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you! Split out to #9055

@konstin konstin force-pushed the konsti/venv-apostrophe branch from 60120d2 to c58a662 Compare November 12, 2024 12:33
@konstin konstin mentioned this pull request Nov 12, 2024
konstin added a commit that referenced this pull request Nov 15, 2024
Move the shlex-like quoting utils in the uv-shell crate, so we only
write `r#"'"'"'"#` once.

Split out from #8984
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uv fails to activate environment in folder with apostrophe

5 participants