Whitespace is not maintained properly when CDATA tags are used --------------------------------------------------------------
Key: IBATISNET-110 URL: http://issues.apache.org/jira/browse/IBATISNET-110 Project: iBatis for .NET Type: Bug Reporter: Ron Grabowski The ParseDynamicTags method in DomSqlMapBuilder.cs calls Trim() when building the sql statement. The following statement: <statement id="GetMany"><![CDATA[SELECT * FROM User ]]></statement> <statement id="GetOne" extends="GetMany"> WHERE Id=3</statement</statement> is incorrectly constructed as: SELECT * FROM UserWHERE Id=3 when it should be: SELECT * FROM User WHERE Id=3 The same error occurs when two or more CDATA nodes and/or a Text node is used inside the same statement. This statement: <statement id="GetMany"> <![CDATA[SELECT * ]]> <![CDATA[FROM ]]> User </statement> is incorrectly rendered as: SELECT *FROMUser This is the offending code: string data = child.InnerText.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim(); //?? One solution is to trim the beginning of the first node and trim the end of the last node: string data = child.InnerText.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' '); if (i == 0) { // trim whitespace from the beginning of the string data = Regex.Replace(data, @"^\s*(.*)$", "$1"); } else if (i == children.Count - 1) { // trim whitespace from the end of the string data = Regex.Replace(data, @"^(.*?)\s*$", "$1"); } Yes, I know there is a TrimStart and TrimEnd method but I think there are more whitespace characters than just " ", "\n", "\t", "\r"...especially if the xml file is encoded with a funky content-type. There may be a more effecient regular expression to remove whitespace. Another solution is to remove the call to Trim after Replace. I think that if the user is using a CDATA node, they probably don't want their sql messed with. Perhaps if we encounter a CDATA node we shouldn't try to make it all fit on one line: trimCdataNodes="false" ??? Thank you to Chad Humphries for encountering this bug. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira