Skip to content

Commit

Permalink
Fix for change in handlebars 2.0
Browse files Browse the repository at this point in the history
Handlebars 2.0 now renders boolean false as the word "false" instead of an empty string. This broke all tests that returned a false value.

Helpers have now been updated to explicitly return an empty string, so as to maintain compatibility with both Handlebars 1.3 and 2.0.

See handlebars-lang/handlebars.js#827
  • Loading branch information
Twipped committed Sep 12, 2014
1 parent cf84fbd commit f704a06
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 34 deletions.
34 changes: 17 additions & 17 deletions build/hoard.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ exports.all = function () {
yes = !!input;
}

if (!options.fn) return yes;
if (!options.fn) return yes || '';

return yes ? options.fn(this) : options.inverse(this);
};
Expand Down Expand Up @@ -314,7 +314,7 @@ exports.any = function () {
yes = !!input;
}

if (!options.fn) return yes;
if (!options.fn) return yes || '';

return yes ? options.fn(this) : options.inverse(this);
};
Expand Down Expand Up @@ -376,7 +376,7 @@ exports.empty = function () {
}

if (!options.fn) {
return yes;
return yes || '';
} else {
return yes ? options.fn(this) : options.inverse(this);
}
Expand Down Expand Up @@ -490,7 +490,7 @@ exports.inArray = function () {
return function (input, value, options) {
var result = input.indexOf(value) >= 0;

if (!options.fn) return result;
if (!options.fn) return result || '';

return result ? options.fn(this) : options.inverse(this);
};
Expand Down Expand Up @@ -646,7 +646,7 @@ exports.notEmpty = function () {
}

if (!options.fn) {
return yes;
return yes || '';
} else {
return yes ? options.fn(this) : options.inverse(this);
}
Expand Down Expand Up @@ -853,15 +853,15 @@ exports.compare = function () {

var result = !!operators[operator](left, right);

if (!options.fn) return result;
if (!options.fn) return result || '';

return result ? options.fn(this) : options.inverse(this);
};
};

exports.gt = function () {
return function (value, test, options) {
if (!options.fn) return value > test;
if (!options.fn) return value > test || '';
if (value > test) {
return options.fn(this);
} else {
Expand All @@ -872,7 +872,7 @@ exports.gt = function () {

exports.gte = function () {
return function (value, test, options) {
if (!options.fn) return value >= test;
if (!options.fn) return value >= test || '';
if (value >= test) {
return options.fn(this);
} else {
Expand All @@ -892,14 +892,14 @@ exports.gte = function () {
exports.has = function () {
return function (input, value, options) {
var result = input.indexOf(value) >= 0;
if (!options.fn) return result;
if (!options.fn) return result || '';
return result ? options.fn(this) : options.inverse(this);
};
};

exports.is = function () {
return function (value, test, options) {
if (!options.fn) return value === test;
if (!options.fn) return value === test || '';
if (value === test) {
return options.fn(this);
} else {
Expand All @@ -910,7 +910,7 @@ exports.is = function () {

exports.isLike = function () {
return function (value, test, options) {
if (!options.fn) return value == test;
if (!options.fn) return value == test || '';
if (value == test) {
return options.fn(this);
} else {
Expand All @@ -921,7 +921,7 @@ exports.isLike = function () {

exports.isnt = function () {
return function (value, test, options) {
if (!options.fn) return value !== test;
if (!options.fn) return value !== test || '';
if (value !== test) {
return options.fn(this);
} else {
Expand All @@ -932,7 +932,7 @@ exports.isnt = function () {

exports.isntLike = function () {
return function (value, test, options) {
if (!options.fn) return value != test;
if (!options.fn) return value != test || '';
if (value != test) {
return options.fn(this);
} else {
Expand All @@ -943,7 +943,7 @@ exports.isntLike = function () {

exports.lt = function () {
return function (value, test, options) {
if (!options.fn) return value < test;
if (!options.fn) return value < test || '';
if (value < test) {
return options.fn(this);
} else {
Expand All @@ -954,7 +954,7 @@ exports.lt = function () {

exports.lte = function () {
return function (value, test, options) {
if (!options.fn) return value <= test;
if (!options.fn) return value <= test || '';
if (value <= test) {
return options.fn(this);
} else {
Expand Down Expand Up @@ -1514,7 +1514,7 @@ exports.endsWith = function () {
var result = haystack.substr(-needle.length) === needle;

if (!options.fn) {
return result;
return result || '';
}

return result ? options.fn(this) : options.inverse(this);
Expand Down Expand Up @@ -2700,7 +2700,7 @@ exports.startsWith = function () {
var result = haystack.substr(0,needle.length) === needle;

if (!options.fn) {
return result;
return result || '';
}

return result ? options.fn(this) : options.inverse(this);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/collection/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.all = function () {
yes = !!input;
}

if (!options.fn) return yes;
if (!options.fn) return yes || '';

return yes ? options.fn(this) : options.inverse(this);
};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/collection/any.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.any = function () {
yes = !!input;
}

if (!options.fn) return yes;
if (!options.fn) return yes || '';

return yes ? options.fn(this) : options.inverse(this);
};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/collection/empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.empty = function () {
}

if (!options.fn) {
return yes;
return yes || '';
} else {
return yes ? options.fn(this) : options.inverse(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/collection/inArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.inArray = function () {
return function (input, value, options) {
var result = input.indexOf(value) >= 0;

if (!options.fn) return result;
if (!options.fn) return result || '';

return result ? options.fn(this) : options.inverse(this);
};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/collection/notEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.notEmpty = function () {
}

if (!options.fn) {
return yes;
return yes || '';
} else {
return yes ? options.fn(this) : options.inverse(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.compare = function () {

var result = !!operators[operator](left, right);

if (!options.fn) return result;
if (!options.fn) return result || '';

return result ? options.fn(this) : options.inverse(this);
};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/gt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.gt = function () {
return function (value, test, options) {
if (!options.fn) return value > test;
if (!options.fn) return value > test || '';
if (value > test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/gte.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.gte = function () {
return function (value, test, options) {
if (!options.fn) return value >= test;
if (!options.fn) return value >= test || '';
if (value >= test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/has.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
exports.has = function () {
return function (input, value, options) {
var result = input.indexOf(value) >= 0;
if (!options.fn) return result;
if (!options.fn) return result || '';
return result ? options.fn(this) : options.inverse(this);
};
};
2 changes: 1 addition & 1 deletion src/helpers/compare/is.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.is = function () {
return function (value, test, options) {
if (!options.fn) return value === test;
if (!options.fn) return value === test || '';
if (value === test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/isLike.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.isLike = function () {
return function (value, test, options) {
if (!options.fn) return value == test;
if (!options.fn) return value == test || '';
if (value == test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/isnt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.isnt = function () {
return function (value, test, options) {
if (!options.fn) return value !== test;
if (!options.fn) return value !== test || '';
if (value !== test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/isntLike.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.isntLike = function () {
return function (value, test, options) {
if (!options.fn) return value != test;
if (!options.fn) return value != test || '';
if (value != test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/lt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.lt = function () {
return function (value, test, options) {
if (!options.fn) return value < test;
if (!options.fn) return value < test || '';
if (value < test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/compare/lte.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exports.lte = function () {
return function (value, test, options) {
if (!options.fn) return value <= test;
if (!options.fn) return value <= test || '';
if (value <= test) {
return options.fn(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/str/endsWith.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.endsWith = function () {
var result = haystack.substr(-needle.length) === needle;

if (!options.fn) {
return result;
return result || '';
}

return result ? options.fn(this) : options.inverse(this);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/str/startsWith.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.startsWith = function () {
var result = haystack.substr(0,needle.length) === needle;

if (!options.fn) {
return result;
return result || '';
}

return result ? options.fn(this) : options.inverse(this);
Expand Down

0 comments on commit f704a06

Please sign in to comment.