about summary refs log tree commit diff
path: root/src/tools/linkchecker
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-10-28 01:11:01 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2017-10-28 17:24:09 +0200
commit6fa521c491b365b354771213186e35c2e2e7a628 (patch)
tree5c6de69264fcb96662ad08ce053c39a631e850cb /src/tools/linkchecker
parent3dafd2c6908f19d573a94b8fc1e99b58460453a8 (diff)
downloadrust-6fa521c491b365b354771213186e35c2e2e7a628.tar.gz
rust-6fa521c491b365b354771213186e35c2e2e7a628.zip
Fix weird bugs
Diffstat (limited to 'src/tools/linkchecker')
-rw-r--r--src/tools/linkchecker/main.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs
index 3ea2e6313af..e0153e1e6f6 100644
--- a/src/tools/linkchecker/main.rs
+++ b/src/tools/linkchecker/main.rs
@@ -69,15 +69,32 @@ struct FileEntry {
 
 type Cache = HashMap<PathBuf, FileEntry>;
 
+fn small_url_encode(s: &str) -> String {
+    s.replace("<", "%3C")
+     .replace(">", "%3E")
+     .replace(" ", "%20")
+     .replace("?", "%3F")
+     .replace("'", "%27")
+     .replace("&", "%26")
+     .replace(",", "%2C")
+     .replace(":", "%3A")
+     .replace(";", "%3B")
+     .replace("[", "%5B")
+     .replace("]", "%5D")
+}
+
 impl FileEntry {
     fn parse_ids(&mut self, file: &Path, contents: &str, errors: &mut bool) {
         if self.ids.is_empty() {
             with_attrs_in_source(contents, " id", |fragment, i, _| {
                 let frag = fragment.trim_left_matches("#").to_owned();
+                let encoded = small_url_encode(&frag);
                 if !self.ids.insert(frag) {
                     *errors = true;
                     println!("{}:{}: id is not unique: `{}`", file.display(), i, fragment);
                 }
+                // Just in case, we also add the encoded id.
+                self.ids.insert(encoded);
             });
         }
     }