UNPKG

2.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.parseDn = void 0;
4function parseDn(seq) {
5 let quoted = false;
6 let key = null;
7 let token = "";
8 let nextNonSpace = 0;
9 seq = seq.trim();
10 const result = new Map();
11 for (let i = 0; i <= seq.length; i++) {
12 if (i === seq.length) {
13 if (key !== null) {
14 result.set(key, token);
15 }
16 break;
17 }
18 const ch = seq[i];
19 if (quoted) {
20 if (ch === '"') {
21 quoted = false;
22 continue;
23 }
24 }
25 else {
26 if (ch === '"') {
27 quoted = true;
28 continue;
29 }
30 if (ch === "\\") {
31 i++;
32 const ord = parseInt(seq.slice(i, i + 2), 16);
33 if (Number.isNaN(ord)) {
34 token += seq[i];
35 }
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 ||
68 seq[nextNonSpace] === "," ||
69 seq[nextNonSpace] === ";" ||
70 (key === null && seq[nextNonSpace] === "=") ||
71 (key !== null && seq[nextNonSpace] === "+")) {
72 i = nextNonSpace - 1;
73 continue;
74 }
75 }
76 token += ch;
77 }
78 return result;
79}
80exports.parseDn = parseDn;
81//# sourceMappingURL=rfc2253Parser.js.map
\No newline at end of file