Skip to content

Commit

Permalink
Fix unescaped quotes in literals
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
lukaslueg committed Dec 3, 2022
1 parent d4e39e6 commit 7b24b13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Removed unused transitive dependency on `time`
- Bump `cargo-lock` to 8.0
- Bump `git2` to 0.14
- Fix unescaped quotes in literals

### Added
- Added GitHub Actions to the list of detected CI platforms
Expand Down
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2017-2020 Lukas Lueg
// Copyright (c) 2017-2022 Lukas Lueg
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -232,7 +232,13 @@ macro_rules! write_variable {

macro_rules! write_str_variable {
($writer:expr, $name:expr, $value:expr, $doc:expr) => {
write_variable!($writer, $name, "&str", format!("r\"{}\"", $value), $doc);
write_variable!(
$writer,
$name,
"&str",
format!("r\"{}\"", $value.escape_default()),
$doc
);
};
}

Expand Down Expand Up @@ -489,11 +495,10 @@ fn write_ci(envmap: &EnvironmentMap, w: &mut fs::File) -> io::Result<()> {
}

fn write_features(envmap: &EnvironmentMap, w: &mut fs::File) -> io::Result<()> {
let prefix = "CARGO_FEATURE_";
let mut features = Vec::new();
for name in envmap.keys() {
if name.starts_with(&prefix) {
features.push(name[prefix.len()..].to_owned());
if let Some(feat) = name.strip_prefix("CARGO_FEATURE_") {
features.push(feat.to_owned());
}
}
features.sort();
Expand Down Expand Up @@ -933,7 +938,7 @@ pub fn write_built_file_with_opts(
manifest_location: &path::Path,
dst: &path::Path,
) -> io::Result<()> {
let mut built_file = fs::File::create(&dst)?;
let mut built_file = fs::File::create(dst)?;
built_file.write_all(
r#"//
// EVERYTHING BELOW THIS POINT WAS AUTO-GENERATED DURING COMPILATION. DO NOT MODIFY.
Expand Down
2 changes: 1 addition & 1 deletion tests/testbox_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() {

fn run(root: &std::path::Path) {
let cargo_result = process::Command::new("cargo")
.current_dir(&root)
.current_dir(root)
.arg("run")
.output()
.expect("cargo failed");
Expand Down

0 comments on commit 7b24b13

Please sign in to comment.