• File: escapeHeaderAttribute.js
  • Full Path: /var/www/nodejs/Notifications_Imali_API/node_modules/@hapi/hoek/lib/escapeHeaderAttribute.js
  • Date Modified: 10/26/1985 3:15 PM
  • File size: 474 bytes
  • MIME-type: text/plain
  • Charset: utf-8
'use strict';

const Assert = require('./assert');


const internals = {};


module.exports = function (attribute) {

    // Allowed value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9, \, "

    Assert(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~\"\\]*$/.test(attribute), 'Bad attribute value (' + attribute + ')');

    return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');                             // Escape quotes and slash
};