Skip to content

Commit 87ef037

Browse files
committed
Don't replace Tabs in CDATA
1 parent f5b29c4 commit 87ef037

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>4.0.18</Version>
3+
<Version>4.0.19</Version>
44
<Authors>Martin Danielsson</Authors>
55
<Company>Haufe-Lexware GmbH &amp; Co. KG</Company>
66
<Description>Extensible, simple and fast ETL Tool</Description>

src/NoFrillsTransformation.Plugins.Acumatica/AcumaticaWriter.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void FinishWrite()
164164
}
165165
_xmlWriter.WriteEndElement(); // row
166166
}
167-
167+
168168
_xmlWriter.WriteEndElement(); // rows
169169
_xmlWriter.WriteEndElement(); // data
170170
_xmlWriter.Close();
@@ -174,7 +174,7 @@ public void FinishWrite()
174174
PostProcess();
175175
}
176176

177-
private void PostProcess()
177+
private void PostProcess()
178178
{
179179
// Acumatica requires all occurrences of tabs inside XML content to be encoded
180180
// as &#x9; instead of the tab character. This is a bit of a pain, but we have to do it.
@@ -188,6 +188,7 @@ private void PostProcess()
188188
using (var writer = new System.IO.StreamWriter(fileNameTarget, false, Encoding.UTF8))
189189
{
190190
string? line;
191+
bool inCData = false;
191192
while ((line = reader.ReadLine()) != null)
192193
{
193194
// Replace all tabs AFTER the first ones on each line (indentations) with &#x9;
@@ -196,7 +197,37 @@ private void PostProcess()
196197
{
197198
firstNonTab++;
198199
}
199-
line = line.Substring(0, firstNonTab) + line.Substring(firstNonTab).Replace("\t", "&#x9;");
200+
// Check for CDATA sections
201+
if (line.Contains("<![CDATA["))
202+
{
203+
// Inside CDATA sections, tabs must NOT be replaced
204+
// Two cases: CDATA ends on the same line, or on a different line
205+
int cdataEnd = line.IndexOf("]]>");
206+
if (cdataEnd > 0)
207+
{
208+
// CDATA ends on the same line
209+
line = line.Substring(0, cdataEnd + 3) + line.Substring(cdataEnd + 3).Replace("\t", "&#x9;");
210+
}
211+
else
212+
{
213+
inCData = true;
214+
}
215+
}
216+
else if (inCData)
217+
{
218+
// We are inside a CDATA section, so we need to check for the end
219+
int cdataEnd = line.IndexOf("]]>");
220+
if (cdataEnd > 0)
221+
{
222+
// CDATA ends on this line
223+
inCData = false;
224+
line = line.Substring(0, cdataEnd + 3) + line.Substring(cdataEnd + 3).Replace("\t", "&#x9;");
225+
}
226+
}
227+
else
228+
{
229+
line = line.Substring(0, firstNonTab) + line.Substring(firstNonTab).Replace("\t", "&#x9;");
230+
}
200231
writer.WriteLine(line);
201232
}
202233
}

0 commit comments

Comments
 (0)