diff --git a/lib/zonefile-node-legacy.js b/lib/zonefile-node-legacy.js index c450ea9..2e5e6ff 100644 --- a/lib/zonefile-node-legacy.js +++ b/lib/zonefile-node-legacy.js @@ -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) { diff --git a/lib/zonefile.js b/lib/zonefile.js index 933ab7a..9ebf275 100644 --- a/lib/zonefile.js +++ b/lib/zonefile.js @@ -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) { diff --git a/package.json b/package.json index 76b070f..34718ee 100644 --- a/package.json +++ b/package.json @@ -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",