2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Added guard to asset helper for missing paths

refs #10496

- currently {{asset this/is/not/a.string}} would throw a 500 error
- this commit changes that to make it throw a sensible 400 + incorrect usage error
This commit is contained in:
Hannah Wolfe 2019-09-09 12:52:55 +01:00
parent 5c8efd087e
commit 9abffe4396
2 changed files with 11 additions and 3 deletions

View file

@ -2,14 +2,19 @@
// Usage: `{{asset "css/screen.css"}}`
//
// Returns the path to the specified asset.
const proxy = require('./proxy');
const {SafeString, metaData, errors, i18n} = require('./proxy');
const get = require('lodash/get');
const {SafeString} = proxy;
const {getAssetUrl} = proxy.metaData;
const {getAssetUrl} = metaData;
module.exports = function asset(path, options) {
const hasMinFile = get(options, 'hash.hasMinFile');
if (!path) {
throw new errors.IncorrectUsageError({
message: i18n.t('warnings.helpers.asset.pathIsRequired')
});
}
return new SafeString(
getAssetUrl(path, hasMinFile)
);

View file

@ -578,6 +578,9 @@
"flagMustBeEnabled": "The {flagName} flag must be enabled in labs if you wish to use the \\{\\{{helperName}\\}\\} helper.",
"seeLink": "See {url}",
"mustBeCalledAsBlock": "The \\{\\{{helperName}\\}\\} helper must be called as a block. E.g. \\{\\{#{helperName}\\}\\} \\{\\{/{helperName}\\}\\}",
"asset": {
"pathIsRequired": "The \\{\\{asset\\}\\} helper must be passed a path"
},
"foreach": {
"iteratorNeeded": "Need to pass an iterator to #foreach"
},