rfc2253Parser.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.parseDn = parseDn;
  6. function parseDn(seq) {
  7. let quoted = false;
  8. let key = null;
  9. let token = "";
  10. let nextNonSpace = 0;
  11. seq = seq.trim();
  12. const result = new Map();
  13. for (let i = 0; i <= seq.length; i++) {
  14. if (i === seq.length) {
  15. if (key !== null) {
  16. result.set(key, token);
  17. }
  18. break;
  19. }
  20. const ch = seq[i];
  21. if (quoted) {
  22. if (ch === '"') {
  23. quoted = false;
  24. continue;
  25. }
  26. } else {
  27. if (ch === '"') {
  28. quoted = true;
  29. continue;
  30. }
  31. if (ch === "\\") {
  32. i++;
  33. const ord = parseInt(seq.slice(i, i + 2), 16);
  34. if (Number.isNaN(ord)) {
  35. token += seq[i];
  36. } else {
  37. i++;
  38. token += String.fromCharCode(ord);
  39. }
  40. continue;
  41. }
  42. if (key === null && ch === "=") {
  43. key = token;
  44. token = "";
  45. continue;
  46. }
  47. if (ch === "," || ch === ";" || ch === "+") {
  48. if (key !== null) {
  49. result.set(key, token);
  50. }
  51. key = null;
  52. token = "";
  53. continue;
  54. }
  55. }
  56. if (ch === " " && !quoted) {
  57. if (token.length === 0) {
  58. continue;
  59. }
  60. if (i > nextNonSpace) {
  61. let j = i;
  62. while (seq[j] === " ") {
  63. j++;
  64. }
  65. nextNonSpace = j;
  66. }
  67. if (nextNonSpace >= seq.length || seq[nextNonSpace] === "," || seq[nextNonSpace] === ";" || key === null && seq[nextNonSpace] === "=" || key !== null && seq[nextNonSpace] === "+") {
  68. i = nextNonSpace - 1;
  69. continue;
  70. }
  71. }
  72. token += ch;
  73. }
  74. return result;
  75. }
  76. //# sourceMappingURL=rfc2253Parser.js.map