Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
handle null base paths and path.join issues on content handler
Browse files Browse the repository at this point in the history
  • Loading branch information
laktek committed Mar 17, 2013
1 parent d5eb71d commit dd38eb2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/content_handler.js
Expand Up @@ -27,6 +27,10 @@ module.exports = {
isSection: function(content_path) {
var self = this;

if (!content_path) {
return false;
}

var path_portions = content_path.split(path.sep || "/");
if (_.any(path_portions, function(portion) { return ( [".", "_"].indexOf(portion[0]) > -1 ); } )) {
return false;
Expand Down Expand Up @@ -212,7 +216,7 @@ module.exports = {
};

var traverse_path = function() {
var current_path = paths_to_traverse.shift();
var current_path = paths_to_traverse.shift() || "";
fs.readdir(path.join(self.contentDir, current_path), function(err, entries) {
if (err) {
throw err;
Expand Down Expand Up @@ -260,6 +264,10 @@ module.exports = {
var self = this;
var collected_contents = [];

if (!basepath) {
return callback("basepath can't be null'", []);
}

// try to read the given path dir
fs.readdir(path.join(self.contentDir, basepath), function(err, files) {
if (err) {
Expand Down
11 changes: 11 additions & 0 deletions spec/content_handler.spec.js
Expand Up @@ -48,6 +48,10 @@ describe("setup", function(){

describe("check for sections", function(){

it("return false if the given path is null", function(){
expect(default_handler.isSection(null)).not.toBeTruthy();
});

it("return true if the given path is a directory", function(){
spyOn(fs, "statSync").andCallFake(function(path){
return {"isDirectory": function(){ return true } };
Expand Down Expand Up @@ -394,6 +398,13 @@ describe("get sections", function(){

describe("get content paths", function(){

it("calls the callback with an error if basepath is null", function(){
var spyCallback = jasmine.createSpy();
default_handler.getContentPaths(null, spyCallback);

expect(spyCallback).toHaveBeenCalledWith("basepath can't be null", []);
});

it("collect all content files (except shared file)", function(){
spyOn(fs, "readdir").andCallFake(function(path, callback){
return callback(null, ["index.json", "page1.json", "page2.json", "_shared"]);
Expand Down

0 comments on commit dd38eb2

Please sign in to comment.