@cullit/config 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +15 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25,6 +25,14 @@ function loadConfig(cwdOrPath = process.cwd()) {
|
|
|
25
25
|
return mergeWithDefaults(resolved);
|
|
26
26
|
}
|
|
27
27
|
function parseSimpleYaml(raw) {
|
|
28
|
+
const RESERVED_KEYS = ["__proto__", "constructor", "prototype"];
|
|
29
|
+
const safeKey = (k) => {
|
|
30
|
+
const trimmed = k.trim();
|
|
31
|
+
if (RESERVED_KEYS.includes(trimmed)) {
|
|
32
|
+
throw new Error(`Config error: reserved key "${trimmed}" is not allowed`);
|
|
33
|
+
}
|
|
34
|
+
return trimmed;
|
|
35
|
+
};
|
|
28
36
|
const result = {};
|
|
29
37
|
let currentSection = "";
|
|
30
38
|
let currentArray = null;
|
|
@@ -37,10 +45,10 @@ function parseSimpleYaml(raw) {
|
|
|
37
45
|
const [key, ...valParts] = trimmed.split(":");
|
|
38
46
|
const val = valParts.join(":").trim();
|
|
39
47
|
if (val) {
|
|
40
|
-
result[key
|
|
48
|
+
result[safeKey(key)] = parseValue(val);
|
|
41
49
|
} else {
|
|
42
|
-
result[key
|
|
43
|
-
currentSection = key
|
|
50
|
+
result[safeKey(key)] = {};
|
|
51
|
+
currentSection = safeKey(key);
|
|
44
52
|
}
|
|
45
53
|
currentArray = null;
|
|
46
54
|
continue;
|
|
@@ -58,7 +66,7 @@ function parseSimpleYaml(raw) {
|
|
|
58
66
|
}
|
|
59
67
|
const obj = {};
|
|
60
68
|
const [k, ...vParts] = content.split(":");
|
|
61
|
-
obj[k
|
|
69
|
+
obj[safeKey(k)] = parseValue(vParts.join(":").trim());
|
|
62
70
|
currentArray.push(obj);
|
|
63
71
|
} else {
|
|
64
72
|
if (currentSection && currentArrayKey) {
|
|
@@ -82,15 +90,15 @@ function parseSimpleYaml(raw) {
|
|
|
82
90
|
if (currentArray && currentArray.length > 0) {
|
|
83
91
|
const lastObj = currentArray[currentArray.length - 1];
|
|
84
92
|
if (typeof lastObj === "object") {
|
|
85
|
-
lastObj[key
|
|
93
|
+
lastObj[safeKey(key)] = parseValue(val);
|
|
86
94
|
continue;
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
if (currentSection) {
|
|
90
|
-
result[currentSection][key
|
|
98
|
+
result[currentSection][safeKey(key)] = parseValue(val);
|
|
91
99
|
}
|
|
92
100
|
} else {
|
|
93
|
-
currentArrayKey = key
|
|
101
|
+
currentArrayKey = safeKey(key);
|
|
94
102
|
currentArray = null;
|
|
95
103
|
if (currentSection) {
|
|
96
104
|
result[currentSection][currentArrayKey] = {};
|