You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
799 B

  1. /**
  2. * Return an ETag in the form of `"<size>-<mtime>"`
  3. * from the given `stat`.
  4. *
  5. * @param {Object} stat
  6. * @return {String}
  7. * @api private
  8. */
  9. exports.etag = function(stat) {
  10. return '"' + stat.size + '-' + Number(stat.mtime) + '"';
  11. };
  12. /**
  13. * decodeURIComponent.
  14. *
  15. * Allows V8 to only deoptimize this fn instead of all
  16. * of send().
  17. *
  18. * @param {String} path
  19. * @api private
  20. */
  21. exports.decode = function(path){
  22. try {
  23. return decodeURIComponent(path);
  24. } catch (err) {
  25. return -1;
  26. }
  27. };
  28. /**
  29. * Escape the given string of `html`.
  30. *
  31. * @param {String} html
  32. * @return {String}
  33. * @api private
  34. */
  35. exports.escape = function(html){
  36. return String(html)
  37. .replace(/&(?!\w+;)/g, '&amp;')
  38. .replace(/</g, '&lt;')
  39. .replace(/>/g, '&gt;')
  40. .replace(/"/g, '&quot;');
  41. };