Skip to content

Commit

Permalink
fix(config): Don't support absolute paths
Browse files Browse the repository at this point in the history
Fixes #319
  • Loading branch information
epage committed Oct 31, 2017
1 parent bb12174 commit 6fd9af9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/config.rs
Expand Up @@ -223,6 +223,15 @@ impl ConfigBuilder {
let mut posts = posts;
posts.default = posts.default.merge(default);

if posts.dir.starts_with('/') {
bail!("posts dir {} must be a relative path", posts.dir)
}
if let Some(ref drafts_dir) = posts.drafts_dir {
if drafts_dir.starts_with('/') {
bail!("posts dir {} must be a relative path", drafts_dir)
}
}

let source = files::cleanup_path(source);
let destination = files::cleanup_path(destination);

Expand Down Expand Up @@ -367,6 +376,11 @@ fn test_from_cwd_not_found() {
});
}

#[test]
fn test_build_default() {
let config = ConfigBuilder::default();
config.build().unwrap();
}
#[test]
fn test_build_dest() {
let result = ConfigBuilder::from_file("tests/fixtures/config/.cobalt.yml").unwrap();
Expand Down Expand Up @@ -411,3 +425,33 @@ fn test_build_abs_dest() {
..Default::default()
});
}

#[test]
fn test_build_posts_rel() {
let mut config = ConfigBuilder::default();
config.posts.dir = "rel".into();
let config = config.build().unwrap();
assert_eq!(config.posts.dir, "rel");
}

#[test]
fn test_build_posts_abs() {
let mut config = ConfigBuilder::default();
config.posts.dir = "/root".into();
assert!(config.build().is_err());
}

#[test]
fn test_build_drafts_rel() {
let mut config = ConfigBuilder::default();
config.posts.drafts_dir = Some("rel".into());
let config = config.build().unwrap();
assert_eq!(config.posts.drafts_dir, Some("rel".into()));
}

#[test]
fn test_build_drafts_abs() {
let mut config = ConfigBuilder::default();
config.posts.drafts_dir = Some("/root".into());
assert!(config.build().is_err());
}

0 comments on commit 6fd9af9

Please sign in to comment.