Skip to content

Commit

Permalink
Merge pull request #624 from blockscout/lok52/empty-file-prefix-bug
Browse files Browse the repository at this point in the history
Fix empty file prefix bug
  • Loading branch information
lok52 authored Oct 18, 2023
2 parents 41fc491 + 55d9764 commit 95236d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions visualizer/visualizer-server/tests/solidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ mod success_advanced_tests {
visualize_contract_success(request, expected_svg).await;
}

#[actix_web::test]
async fn uml_empty_file_name() {
let contract_path = format!("{CONTRACTS_DIR}/SimpleContract.sol",);
let contract =
fs::read_to_string(&contract_path).expect("Error while reading SimpleContract.sol");
let svg_path = format!("{SAMPLES_DIR}/uml/simple_contract.svg",);
let expected_svg = fs::read_to_string(&svg_path)
.unwrap_or_else(|_| panic!("Error while reading simple_contract.svg",));
let request = json!({
"sources": {
".sol": contract,
}
});
visualize_contract_success(request, expected_svg).await;
}

// filename that starts with @
#[actix_web::test]
async fn uml_starting_at_sign() {
Expand Down
7 changes: 7 additions & 0 deletions visualizer/visualizer/src/solidity/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ pub async fn save_files(root: &Path, files: BTreeMap<PathBuf, String>) -> Result
));
}

// Set a default file prefix if none is provided
let name = if name.ends_with(".sol") {
name.with_file_name("main.sol")
} else {
name
};

let file_path = root.join(name);
let prefix = file_path.parent();
if let Some(prefix) = prefix {
Expand Down

0 comments on commit 95236d9

Please sign in to comment.