Ohm-Management - Projektarbeit B-ME
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.

index.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. const replacements = {
  3. /* search filter replacements */
  4. filter: {
  5. '\u0000': '\\00', // NUL
  6. '\u0028': '\\28', // (
  7. '\u0029': '\\29', // )
  8. '\u002a': '\\2a', // *
  9. '\u005c': '\\5c' // \
  10. },
  11. /* distinguished name replacements */
  12. dnBegin: {
  13. '\u0020': '\\ ', // SPC
  14. },
  15. dn: {
  16. '\u0022': '\\"', // "
  17. '\u0023': '\\#', // #
  18. '\u002b': '\\+', // +
  19. '\u002c': '\\,', // ,
  20. '\u003b': '\\;', // ;
  21. '\u003c': '\\<', // <
  22. '\u003d': '\\=', // =
  23. '\u003e': '\\>', // >
  24. '\u005c': '\\\\' // \
  25. },
  26. dnEnd: {
  27. '\u0020': '\\ ' // SPC
  28. }
  29. };
  30. module.exports = {
  31. filter: function filter(strings, ...values) {
  32. let safe = '';
  33. strings.forEach((string, i) => {
  34. safe += string;
  35. if (values.length > i) {
  36. safe += `${values[i]}`.replace(/(\u0000|\u0028|\u0029|\u002a|\u005c)/gm, (ch) => replacements.filter[ch]);
  37. }
  38. });
  39. return safe;
  40. },
  41. dn: function dn(strings, ...values) {
  42. let safe = '';
  43. strings.forEach((string, i) => {
  44. safe += string;
  45. if (values.length > i) {
  46. safe += `${values[i]}`
  47. .replace(/(\u0022|\u0023|\u002b|\u002c|\u003b|\u003c|\u003d|\u003e|\u005c)/gm, (ch) => replacements.dn[ch])
  48. .replace(/^(\u0020)/gm, (ch) => replacements.dnBegin[ch])
  49. .replace(/(\u0020)$/gm, (ch) => replacements.dnEnd[ch]);
  50. }
  51. });
  52. return safe;
  53. },
  54. };