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