This project has moved and is read-only. For the latest updates, please go here.

EdiFabric Escape Character Issue

May 6, 2015 at 12:21 PM
Hi to all developers of this amazing code library,

EdiFabric has made the serialization / deserialization of edi messages a convenience, and I would like to thank you for that.

I have picked up a bug importing an Edifact_D96B_CUSRES message from German Customs. This particular test case tested our ability to handle the Edifact interchange context when used within a specific element using a series of escape characters(‘?’).

NAD+AA+++Für Rechnung (Name) Schimmel, Schni:p´s und Schnapp & Co., Metzgereitec:hnik; Meisterbetrieb GmbH & Co. KG:§@ß|<B>=uml?'?+?:??+Für Rechnung (Ortsteil) ÄÜÖ?:-)?+???'&§+Für Rechnung (Ort) römische Provinz++IT-B 6789+IT'

The issue lies with ??+Für Rechnung (Ortsteil) ÄÜÖ?:-) , EdiFabric escapes the + when preceded by ?? (it picks up the previous symbol is ?, which should be an escaped ?). This causes the segment to build up its components incorrectly.

If you have any fixes for this scenario, please let me know.

Kind Regards,

May 12, 2015 at 9:32 AM

This has now been resolved - please update to the latest release (5.3).

May 12, 2015 at 11:23 AM
Thank you so much.

Keep up the great work.

Kind Regards,

Nov 20, 2015 at 10:33 AM
Edited Nov 20, 2015 at 10:34 AM

I've just encountered another instance where an escaped-escape character (??) was not being deserialized correctly. What happens is, if an escaped character (?) is escaped (??), the deserialised variable doesn't replace the double question marks with a single question mark (?? should be ?). Another issue is 3 question marks followed by a segment seperator (???'). When deserialized, the ???' removes (trims) all preceding question marks.

I've created a fix for this bug, might not be as elegant as your code, but it does the trick:

line = line.Remove(line.Length - 1) removes only the preceding escape character.
line = line + symbol only adds to the line string if both previous and current symbols does not equal an escape character

private static string[] EscapeSplit(this string contents, char escapeCharacter, char splitSeparator, StringSplitOptions splitOption)
            var result = new List<string>();
            var line = "";
            char previousSymbol = char.MinValue;

            // Iterate through all chars in the string
            // This builds a line until the split separator is reached
            // Only if the split separator is not escaped, e.g. not preceded by the escape character
            foreach (char symbol in contents)
                // If the current char is the split separator
                if (symbol == splitSeparator)
                    // Check if the separator is escaped
                    if (previousSymbol != escapeCharacter)
                        // If it not escaped, add the currently built line
                        // and start the next line
                        // check for escaping the escape character
                        if (line.EndsWith(new string(new[] { escapeCharacter, escapeCharacter })))
                            line = line.Remove(line.Length - 1);

                        line = "";
                        previousSymbol = char.MinValue;


                    line = line.Remove(line.Length - 1);
                    // Keep building the line until a separator is reached
                    //line = line.TrimEnd(escapeCharacter);

                //line = line + symbol;

                // //Keep track of the previous character in case it's an escape character
                //if (previousSymbol == symbol && previousSymbol == escapeCharacter)
                //    previousSymbol = char.MinValue;
                //    previousSymbol = symbol;

                if (previousSymbol == symbol && previousSymbol == escapeCharacter)
                    previousSymbol = char.MinValue;
                    previousSymbol = symbol;
                    line = line + symbol;


            // Handle blank lines
            if (splitOption == StringSplitOptions.RemoveEmptyEntries)

            return result.ToArray();
Kind Regards, and thank you once again.