about summary refs log tree commit diff
path: root/src/tools/jsondocck
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2023-07-11 16:31:33 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2023-07-12 10:45:49 +0200
commit18457ea47db3c923b617159640211a23f88f6fcf (patch)
treecdaf05bb47104fd5e49132ee4ce0c75d98d7a6c9 /src/tools/jsondocck
parentb12ff66f2c9daf6538fe0548b3c2ba16d9185cfb (diff)
downloadrust-18457ea47db3c923b617159640211a23f88f6fcf.tar.gz
rust-18457ea47db3c923b617159640211a23f88f6fcf.zip
Allow to have `-` in the rustdoc-json test file name
Diffstat (limited to 'src/tools/jsondocck')
-rw-r--r--src/tools/jsondocck/src/cache.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/tools/jsondocck/src/cache.rs b/src/tools/jsondocck/src/cache.rs
index f9e54232750..50697d46b8c 100644
--- a/src/tools/jsondocck/src/cache.rs
+++ b/src/tools/jsondocck/src/cache.rs
@@ -15,8 +15,10 @@ impl Cache {
     /// Create a new cache, used to read files only once and otherwise store their contents.
     pub fn new(config: &Config) -> Cache {
         let root = Path::new(&config.doc_dir);
-        let filename = Path::new(&config.template).file_stem().unwrap();
-        let file_path = root.join(&Path::with_extension(Path::new(filename), "json"));
+        // `filename` needs to replace `-` with `_` to be sure the JSON path will always be valid.
+        let filename =
+            Path::new(&config.template).file_stem().unwrap().to_str().unwrap().replace('-', "_");
+        let file_path = root.join(&Path::with_extension(Path::new(&filename), "json"));
         let content = fs::read_to_string(&file_path).expect("failed to read JSON file");
 
         Cache {