How to use the @hapi/hoek.escapeHtml function in @hapi/hoek

To help you get started, we’ve selected a few @hapi/hoek examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hapijs / hapi / lib / validation.js View on Github external
}
    }

    if (request.route.settings.validate.failAction === 'ignore') {
        return;
    }

    // Prepare error

    const defaultError = validationError.isBoom ? validationError : Boom.badRequest(`Invalid request ${source} input`);
    const detailedError = Boom.boomify(validationError, { statusCode: 400, override: false });
    detailedError.output.payload.validation = { source, keys: [] };
    if (validationError.details) {
        for (const details of validationError.details) {
            const path = details.path;
            detailedError.output.payload.validation.keys.push(Hoek.escapeHtml(path.join('.')));
        }
    }

    if (request.route.settings.validate.errorFields) {
        for (const field in request.route.settings.validate.errorFields) {
            detailedError.output.payload[field] = request.route.settings.validate.errorFields[field];
        }
    }

    return request._core.toolkit.failAction(request, request.route.settings.validate.failAction, defaultError, { details: detailedError, tags: ['validation', 'error', source] });
};
github hapijs / lab / lib / reporters / html.js View on Github external
Handlebars.registerHelper('lintJoin', (array) => {

        let str = '';

        for (let i = 0; i < array.length; ++i) {
            if (str) {
                str += '
'; // This is a line break
            }

            str += Hoek.escapeHtml(array[i]); // Handlebars' escape is just not enough
        }

        return new Handlebars.SafeString(str);
    });
github hapijs / lab / lib / reporters / html.js View on Github external
Handlebars.registerHelper('errorStack', (err) => {

        const stack = err.stack.slice(err.stack.indexOf('\n') + 1).replace(/^\s*/gm, '  ');
        return new Handlebars.SafeString(Hoek.escapeHtml(stack));
    });
github hapijs / inert / lib / directory.js View on Github external
internals.generateListing = async function (path, resource, selection, hasTrailingSlash, settings, request) {

    let files;
    try {
        files = await Fs.readdir(path);
    }
    catch (err) {
        Bounce.rethrow(err, 'system');
        throw Boom.internal('Error accessing directory', err);
    }

    resource = decodeURIComponent(resource);
    const display = Hoek.escapeHtml(resource);
    let html = '<title>' + display + '</title><h1>Directory: ' + display + '</h1><ul>';

    if (selection) {
        const parent = resource.substring(0, resource.lastIndexOf('/', resource.length - (hasTrailingSlash ? 2 : 1))) + '/';
        html = html + '<li><a href="' + internals.pathEncode(parent) + '">Parent Directory</a></li>';
    }

    for (let i = 0; i &lt; files.length; ++i) {
        if (settings.showHidden ||
            !internals.isFileHidden(files[i])) {

            html = html + '<li><a href="' + internals.pathEncode(resource + (!hasTrailingSlash ? '/' : '') + files[i]) + '">' + Hoek.escapeHtml(files[i]) + '</a></li>';
        }
    }

    html = html + '</ul>';
github hapijs / lab / lib / reporters / html.js View on Github external
Handlebars.registerHelper('errorMessage', (err) => {

        return new Handlebars.SafeString(Hoek.escapeHtml('' + err.message));
    });
github hapijs / lab / lib / reporters / html.js View on Github external
entry.errors.forEach((err) => {

                err.message = Hoek.escapeHtml(err.message);
            });
        }, this);
github hapijs / inert / lib / directory.js View on Github external
}

    resource = decodeURIComponent(resource);
    const display = Hoek.escapeHtml(resource);
    let html = '<title>' + display + '</title><h1>Directory: ' + display + '</h1><ul>';

    if (selection) {
        const parent = resource.substring(0, resource.lastIndexOf('/', resource.length - (hasTrailingSlash ? 2 : 1))) + '/';
        html = html + '<li><a href="' + internals.pathEncode(parent) + '">Parent Directory</a></li>';
    }

    for (let i = 0; i &lt; files.length; ++i) {
        if (settings.showHidden ||
            !internals.isFileHidden(files[i])) {

            html = html + '<li><a href="' + internals.pathEncode(resource + (!hasTrailingSlash ? '/' : '') + files[i]) + '">' + Hoek.escapeHtml(files[i]) + '</a></li>';
        }
    }

    html = html + '</ul>';

    return request.generateResponse(html);
};