about summary refs log tree commit diff
path: root/src/librustdoc/html/render
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-04-17 17:44:16 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2020-04-17 18:09:04 +0200
commitb4fb3069ce82f61f84a9487d17fb96389d55126a (patch)
tree505141f12fa16a8461d0e6716716c5f9174cc8e3 /src/librustdoc/html/render
parent4e4d49d60fd696c4036d438292673a2d7fd34519 (diff)
downloadrust-b4fb3069ce82f61f84a9487d17fb96389d55126a.tar.gz
rust-b4fb3069ce82f61f84a9487d17fb96389d55126a.zip
Replace big JS dict with JSON parsing
Diffstat (limited to 'src/librustdoc/html/render')
-rw-r--r--src/librustdoc/html/render/cache.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs
index a8efb16a1d3..03aa5d519c6 100644
--- a/src/librustdoc/html/render/cache.rs
+++ b/src/librustdoc/html/render/cache.rs
@@ -631,7 +631,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
 
     // Collect the index into a string
     format!(
-        r#"searchIndex["{}"] = {};"#,
+        r#""{}":{}"#,
         krate.name,
         serde_json::to_string(&CrateData {
             doc: crate_doc,
@@ -639,6 +639,11 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
             paths: crate_paths,
         })
         .expect("failed serde conversion")
+        // All these `replace` calls are because we have to go through JS string for JSON content.
+        .replace(r"\", r"\\")
+        .replace("'", r"\'")
+        // We need to escape double quotes for the JSON.
+        .replace("\\\"", "\\\\\"")
     )
 }