1
mirror of https://github.com/jakejarvis/hoot.git synced 2025-10-18 20:14:25 -04:00

Refactor DNS answer normalization and improve quote trimming function

This commit is contained in:
2025-09-23 20:30:57 -04:00
parent fba7bd93db
commit 0d74e85f13

View File

@@ -105,17 +105,16 @@ async function normalizeAnswer(
const ttl = a.TTL;
switch (type) {
case "A":
case "AAAA":
case "NS": {
case "AAAA": {
const value = trimDot(a.data);
const isCloudflare =
type === "A" || type === "AAAA"
? await isCloudflareIpAsync(value)
: false;
const isCloudflare = await isCloudflareIpAsync(value);
return { type, name, value, ttl, isCloudflare };
}
case "NS": {
return { type, name, value: trimDot(a.data), ttl };
}
case "TXT":
return { type, name, value: stripTxtQuotes(a.data), ttl };
return { type, name, value: trimQuotes(a.data), ttl };
case "MX": {
const [prioStr, ...hostParts] = a.data.split(" ");
const priority = Number(prioStr);
@@ -134,7 +133,7 @@ async function normalizeAnswer(
function trimDot(s: string) {
return s.endsWith(".") ? s.slice(0, -1) : s;
}
function stripTxtQuotes(s: string) {
function trimQuotes(s: string) {
// Cloudflare may return quoted strings; remove leading/trailing quotes
return s.replace(/^"|"$/g, "");
}