diff --git a/src/modules/python.rs b/src/modules/python.rs index df4cfab5..29974163 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -121,8 +121,9 @@ fn get_python_virtual_env(context: &Context) -> Option { }) }) } + fn get_prompt_from_venv(venv_path: &Path) -> Option { - Ini::load_from_file(venv_path.join("pyvenv.cfg")) + Ini::load_from_file_noescape(venv_path.join("pyvenv.cfg")) .ok()? .general_section() .get("prompt") @@ -424,6 +425,33 @@ prompt = '(foo)' dir.close() } + #[test] + fn with_active_venv_and_line_break_like_prompt() -> io::Result<()> { + let dir = tempfile::tempdir()?; + create_dir_all(dir.path().join("my_venv"))?; + let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?; + venv_cfg.write_all( + br" +home = something +prompt = foo\nbar + ", + )?; + venv_cfg.sync_all()?; + + let actual = ModuleRenderer::new("python") + .path(dir.path()) + .env("VIRTUAL_ENV", dir.path().join("my_venv").to_str().unwrap()) + .collect(); + + let expected = Some(format!( + "via {}", + Color::Yellow.bold().paint(r"🐍 v3.8.0 (foo\nbar) ") + )); + + assert_eq!(actual, expected); + dir.close() + } + fn check_python2_renders(dir: &tempfile::TempDir, starship_config: Option) { let config = starship_config.unwrap_or(toml::toml! { [python]