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

Properly handle cases where options contain line feed characters #43

Merged
merged 1 commit into from
Jun 22, 2023
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.71"
base64 = "0.21.2"
bzip2 = "0.4.4"
clap = { version = "4.2.5", features = ["derive"] }
directories = "5.0.0"
Expand All @@ -23,9 +24,10 @@ zip = { version = "0.6.4", features = ["deflate"] }
zstd = "0.12.3"

[build-dependencies]
rand = "0.8.5"
base64 = "0.21.2"
flate2 = "1.0.26"
highway = "1.0.0"
rand = "0.8.5"
regex = "1.8.1"
reqwest = { version = "0.11", features = ["blocking", "rustls-tls"], default-features = false }
tar = "0.4.38"
Expand Down
7 changes: 5 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::hash::{Hash, Hasher};
use std::io::Read;
use std::path::PathBuf;

use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _};
use highway::PortableHash;
use rand::distributions::{Alphanumeric, DistString};
use regex::Regex;
Expand Down Expand Up @@ -349,10 +350,12 @@ fn set_project_dependency_file(dependency_file: &str) {
}

let file_name = path.file_name().unwrap().to_str().unwrap();
let contents = fs::read_to_string(dependency_file)
.unwrap_or_else(|_| panic!("\n\nFailed to read dependency file {dependency_file}\n\n"));

set_runtime_variable(
"PYAPP_PROJECT_DEPENDENCY_FILE",
fs::read_to_string(dependency_file)
.unwrap_or_else(|_| panic!("\n\nFailed to read dependency file {dependency_file}\n\n")),
STANDARD_NO_PAD.encode(contents.as_bytes()),
);
set_runtime_variable("PYAPP__PROJECT_DEPENDENCY_FILE_NAME", file_name);
}
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

***Fixed:***

- Properly handle cases where options contain line feed characters

## 0.9.0 - 2023-06-21

***Changed:***
Expand Down
14 changes: 12 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _};
use directories::ProjectDirs;
use once_cell::sync::OnceCell;

Expand All @@ -23,6 +24,15 @@ pub fn initialize() -> Result<()> {
Ok(())
}

fn decode_option(encoded: &'static str) -> String {
String::from_utf8(
STANDARD_NO_PAD
.decode(encoded)
.unwrap_or_else(|_| panic!("{} is not valid base64", encoded)),
)
.unwrap_or_else(|_| panic!("{} is not valid UTF-8", encoded))
}

pub fn embedded_distribution() -> &'static [u8] {
// If this is empty, then the distribution will be downloaded at runtime
include_bytes!("embed/distribution")
Expand Down Expand Up @@ -78,7 +88,7 @@ pub fn project_version() -> String {
}

pub fn project_dependency_file() -> String {
env!("PYAPP_PROJECT_DEPENDENCY_FILE").into()
decode_option(env!("PYAPP_PROJECT_DEPENDENCY_FILE"))
}

pub fn project_dependency_file_name() -> String {
Expand All @@ -94,7 +104,7 @@ pub fn exec_module() -> String {
}

pub fn exec_code() -> String {
env!("PYAPP_EXEC_CODE").into()
decode_option(env!("PYAPP_EXEC_CODE"))
}

pub fn pip_extra_args() -> String {
Expand Down