Percent decode path segments of URL

This commit is contained in:
Magnus Hoff 2017-10-01 23:24:16 +02:00
parent 804bfa074c
commit 7562961093
4 changed files with 10 additions and 2 deletions

1
Cargo.lock generated
View file

@ -580,6 +580,7 @@ dependencies = [
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -28,6 +28,7 @@ chrono = "0.4"
clap = "2.26" clap = "2.26"
bart = "0.1.4" bart = "0.1.4"
bart_derive = "0.1.4" bart_derive = "0.1.4"
percent-encoding = "1.0.0"
[dependencies.libsqlite3-sys] [dependencies.libsqlite3-sys]
features = ["bundled"] features = ["bundled"]

View file

@ -12,6 +12,7 @@ extern crate clap;
extern crate futures; extern crate futures;
extern crate futures_cpupool; extern crate futures_cpupool;
extern crate hyper; extern crate hyper;
extern crate percent_encoding;
extern crate pulldown_cmark; extern crate pulldown_cmark;
extern crate r2d2; extern crate r2d2;
extern crate r2d2_diesel; extern crate r2d2_diesel;

View file

@ -1,6 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use futures::{Future, finished}; use futures::{Future, finished, failed};
use percent_encoding::percent_decode;
use assets::*; use assets::*;
use article_resource::ArticleResource; use article_resource::ArticleResource;
@ -66,7 +67,11 @@ impl Lookup for WikiLookup {
let mut split = path[1..].split('/'); let mut split = path[1..].split('/');
let slug = split.next().expect("Always at least one element").to_owned(); let slug = split.next().expect("Always at least one element");
let slug = match percent_decode(slug.as_bytes()).decode_utf8() {
Ok(x) => x,
Err(x) => return Box::new(failed(x.into()))
}.to_string();
if split.next() != None { if split.next() != None {
// Currently disallow any URLs of the form /slug/... // Currently disallow any URLs of the form /slug/...