express-hbs 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/hbs.js CHANGED
@@ -348,7 +348,7 @@ ExpressHbs.prototype.compile = function (source, filename) {
348
348
  if (typeof source !== 'string') {
349
349
  throw new Error('registerPartial must be a string for empty comment workaround');
350
350
  }
351
- if (source.indexOf('}}') === source.length - 2) {
351
+ if (source.length >= 2 && source.indexOf('}}') === source.length - 2) {
352
352
  source += ' ';
353
353
  }
354
354
 
@@ -643,10 +643,16 @@ ExpressHbs.prototype.___express = function ___express(filename, source, options,
643
643
  Object.keys(values).forEach(function (key) {
644
644
  values[key] = replaceValue(values, values[key]);
645
645
  });
646
- res = replaceValue(values, res);
647
- if (resolver.hasResolvers(res)) {
648
- return handleAsync(null, res);
646
+ var replaced = replaceValue(values, res);
647
+ // Re-check against the live cache: nested async helpers may have registered new IDs
648
+ // while resolving. Stop if a pass made no progress so unknown IDs can never loop forever.
649
+ if (
650
+ replaced !== res &&
651
+ resolver.hasResolvers(replaced, options.resolverCache, self.Utils.escapeExpression)
652
+ ) {
653
+ return handleAsync(null, replaced);
649
654
  }
655
+ res = replaced;
650
656
  cb(null, res);
651
657
  });
652
658
  }
package/lib/resolver.js CHANGED
@@ -42,14 +42,21 @@ function done(cache, callback) {
42
42
  });
43
43
  }
44
44
 
45
- function hasResolvers(text) {
45
+ function hasResolvers(text, cache, escape) {
46
46
  // NOTE: We specifically search the text for the ID_PREFIX **NOT** including the escapable character
47
47
  // This is because that character can be escaped in the text, and lead us to not finding unresolved
48
48
  // async helper outputs.
49
- if (text.search(ID_PREFIX) >= 0) {
49
+ if (text.indexOf(ID_PREFIX) < 0) {
50
+ return false;
51
+ }
52
+ if (!cache) {
50
53
  return true;
51
54
  }
52
- return false;
55
+ // Only report IDs that were actually generated by an async helper. The prefix can also
56
+ // appear in user-supplied data, which must never be treated as an unresolved helper.
57
+ return Object.keys(cache).some(function (id) {
58
+ return text.indexOf(id) >= 0 || (escape && text.indexOf(escape(id)) >= 0);
59
+ });
53
60
  }
54
61
 
55
62
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-hbs",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Express handlebars template engine complete with multiple layouts, partials and blocks.",
5
5
  "keywords": [
6
6
  "express4",
@@ -28,7 +28,7 @@
28
28
  "author": "Mario Gutierrez <mario@barc.com>",
29
29
  "license": "MIT",
30
30
  "devDependencies": {
31
- "@tryghost/pro-ship": "2.0.1",
31
+ "@tryghost/pro-ship": "2.0.3",
32
32
  "cookie-parser": "1.4.7",
33
33
  "express": "5.3.0",
34
34
  "i18n": "0.15.4",