Merge pull request #21947 from DEV-DIBSTER/main

chore: create testing file
This commit is contained in:
William Harrison authored and GitHub committed 2025-04-11 11:49:25 +08:00
commit 53cc0cda16
1 file changed
+35 -19
+35 -19
View File
@@ -36,30 +36,46 @@ const domainsPath = path.resolve("domains");
const files = fs.readdirSync(domainsPath); const files = fs.readdirSync(domainsPath);
function findDuplicateKeys(jsonString) { function findDuplicateKeys(jsonString) {
const duplicateKeys = []; const duplicateKeys = new Set();
const keyStack = [];
const stack = []; const keyRegex = /"(.*?)"\s*:/g;
const obj = JSON.parse(jsonString, (key, value) => { let i = 0;
if (typeof key === "string") { while (i < jsonString.length) {
const current = stack[stack.length - 1]; const char = jsonString[i];
if (current) {
if (current[key]) { if (char === "{") {
duplicateKeys.push(key); keyStack.push({});
} else { i++;
current[key] = true; continue;
} }
if (char === "}") {
keyStack.pop();
i++;
continue;
}
keyRegex.lastIndex = i;
const match = keyRegex.exec(jsonString);
if (match && match.index === i && keyStack.length > 0) {
const key = match[1];
const currentScope = keyStack[keyStack.length - 1];
if (currentScope[key]) {
duplicateKeys.add(key);
} else {
currentScope[key] = true;
} }
i = keyRegex.lastIndex;
} else {
i++;
} }
}
if (typeof value === "object" && value !== null) { return [...duplicateKeys];
stack.push({});
}
return value;
});
return [...new Set(duplicateKeys)];
} }
async function validateFields(t, obj, fields, file, prefix = "") { async function validateFields(t, obj, fields, file, prefix = "") {