Skip to content

Commit

Permalink
Fixed flattening soa modifies txt.
Browse files Browse the repository at this point in the history
  • Loading branch information
elgs committed May 17, 2023
1 parent ec9f1cd commit 8e5bc1b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
18 changes: 6 additions & 12 deletions lib/zonefile-node-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,14 @@ let removeComments = function (text) {
};

let flatten = function (text) {
let captured = [];
let re = /\([\s\S]*?\)/gim;
let soa;
let re = /SOA[\s\S]*?\([\s\S]*?\)/gim;
let match = re.exec(text);
while (match !== null) {
match.replacement = match[0].replace(/\s+/gm, ' ');
captured.push(match);
// captured Text, index, input
match = re.exec(text);
if (match !== null) {
soa = match[0].replace(/\s+/gm, ' ');
}
let arrText = text.split('');
for (match of captured) {
arrText.splice(match.index, match[0].length, match.replacement);
}
return arrText.join('').replace(/\(|\)/gim, ' ');
soa = soa.replace(/\(|\)/gim, ' ');
return text.substring(0, match.index) + soa + text.substring(match.index + match[0].length);
};

let normalizeRR = function (rr) {
Expand Down
18 changes: 6 additions & 12 deletions lib/zonefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,14 @@ let removeComments = function (text) {
};

let flatten = function (text) {
let captured = [];
let re = /\([\s\S]*?\)/gim;
let soa;
let re = /SOA[\s\S]*?\([\s\S]*?\)/gim;
let match = re.exec(text);
while (match !== null) {
match.replacement = match[0].replace(/\s+/gm, ' ');
captured.push(match);
// captured Text, index, input
match = re.exec(text);
if (match !== null) {
soa = match[0].replace(/\s+/gm, ' ');
}
let arrText = text.split('');
for (match of captured) {
arrText.splice(match.index, match[0].length, match.replacement);
}
return arrText.join('').replace(/\(|\)/gim, ' ');
soa = soa.replace(/\(|\)/gim, ' ');
return text.substring(0, match.index) + soa + text.substring(match.index + match[0].length);
};

let normalizeRR = function (rr) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dns-zonefile",
"version": "0.3.0",
"version": "0.3.1",
"description": "A DNS zone file parser and generator.",
"main": "./lib/zonefile.js",
"types": "./lib/zonefile.d.ts",
Expand Down

0 comments on commit 8e5bc1b

Please sign in to comment.