escapeHeaderAttribute.js 474 B

12345678910111213141516
  1. 'use strict';
  2. const Assert = require('./assert');
  3. const internals = {};
  4. module.exports = function (attribute) {
  5. // Allowed value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9, \, "
  6. Assert(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~\"\\]*$/.test(attribute), 'Bad attribute value (' + attribute + ')');
  7. return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"'); // Escape quotes and slash
  8. };