Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 06f3ba0

Browse files
rjchowNebulis
authored andcommitted
fix: remove double quotes if they exist maybe
1 parent 320ddfd commit 06f3ba0

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ describe("parseDocumentStoreResults", () => {
6868
},
6969
]);
7070
});
71+
test("it should correctly handle cases where the TXT record is not double quoted", () => {
72+
const sampleRecord = [
73+
{
74+
name: "example.openattestation.com.",
75+
type: 16,
76+
TTL: 110,
77+
data: "openatts net=ethereum netId=3 addr=0x2f60375e8144e16Adf1979936301D8341D58C36C",
78+
dnssec: true,
79+
},
80+
];
81+
expect(parseDocumentStoreResults(sampleRecord, true)).toStrictEqual([
82+
{
83+
type: "openatts",
84+
net: "ethereum",
85+
netId: "3",
86+
addr: "0x2f60375e8144e16Adf1979936301D8341D58C36C",
87+
dnssec: true,
88+
},
89+
]);
90+
});
7191
test("it should return two record items if there are two openatts record", () => {
7292
const sampleRecord = [
7393
{

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ const applyDnssecResults = <T>(dnssecStatus: boolean) => (record: T): T => {
8484
return { ...record, dnssec: dnssecStatus };
8585
};
8686

87+
/**
88+
* Some DNS servers return TXT records with quoted strings, others don't :D
89+
* @param record
90+
* @returns unquoted DNS record
91+
*/
92+
const trimDoubleQuotes = (record: string) => {
93+
return record.startsWith('"') ? record.slice(1, -1) : record;
94+
};
95+
8796
/**
8897
* Takes a record set and breaks that info array of key value pairs
8998
* @param recordSet e.g: [{name: "google.com", type: 16, TTL: 3599, data: '"openatts net=ethereum netId=3 addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"}]
@@ -92,7 +101,7 @@ const parseOpenAttestationRecords = (recordSet: IDNSRecord[] = []): GenericObjec
92101
trace(`Parsing DNS results: ${JSON.stringify(recordSet)}`);
93102
return recordSet
94103
.map((record) => record.data)
95-
.map((record) => record.slice(1, -1)) // removing leading and trailing quotes
104+
.map(trimDoubleQuotes) // removing leading and trailing quotes if they exist
96105
.filter(isOpenAttestationRecord)
97106
.map(parseOpenAttestationRecord);
98107
};

0 commit comments

Comments
 (0)