Permalink
Browse files

handle null base paths and path.join issues on content handler

  • Loading branch information...
1 parent d5eb71d commit dd38eb2d5465ec2b6a2dd523499f3db8a2d928a4 @laktek committed Mar 17, 2013
Showing with 20 additions and 1 deletion.
  1. +9 −1 lib/content_handler.js
  2. +11 −0 spec/content_handler.spec.js
View
@@ -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;
@@ -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;
@@ -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) {
@@ -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 } };
@@ -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"]);

0 comments on commit dd38eb2

Please sign in to comment.