You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2020/11/24 03:16:57 UTC

[royale-asjs] branch develop updated: Addresses #947, swapped to use of String.trim() selectively for areas where needed.

This is an automated email from the ASF dual-hosted git repository.

gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new e0dcd7b  Addresses #947, swapped to use of String.trim() selectively for areas where needed.
e0dcd7b is described below

commit e0dcd7b199ac559709f9a35b301e49c75aaaa6d3
Author: greg-dove <gr...@gmail.com>
AuthorDate: Tue Nov 24 16:16:36 2020 +1300

    Addresses #947, swapped to use of String.trim() selectively for areas where needed.
---
 frameworks/projects/XML/src/main/royale/XML.as     | 20 +++++++++--------
 .../flexUnitTests/xml/XMLTesterGeneralTest.as      | 25 +++++++++++++++++++++-
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/frameworks/projects/XML/src/main/royale/XML.as b/frameworks/projects/XML/src/main/royale/XML.as
index 2dd7cf5..27c7103 100644
--- a/frameworks/projects/XML/src/main/royale/XML.as
+++ b/frameworks/projects/XML/src/main/royale/XML.as
@@ -468,11 +468,7 @@ package
 			return false;
 		}
 		
-		static private function trimXMLWhitespace(value:String):String
-		{
-			return value.replace(/^\s+|\s+$/gm,'');
-		}
-		
+
 		/**
 		 * [static] Returns an object with the following properties set to the default values: ignoreComments, ignoreProcessingInstructions, ignoreWhitespace, prettyIndent, and prettyPrinting.
 		 * @return
@@ -568,10 +564,11 @@ package
 			// _children = [];
 			if(xml != null)
 			{
-				var xmlStr:String = ignoreWhitespace ? trimXMLWhitespace("" + xml) : "" + xml;
+				var xmlStr:String = "" + xml;
 				if(xmlStr.indexOf("<") == -1)
 				{
 					// _nodeKind = TEXT;
+					if (ignoreWhitespace) xmlStr = xmlStr.trim();
 					_value = xmlStr;
 				}
 				else
@@ -634,7 +631,7 @@ package
 			
 			var decl:String = xmlDecl.exec(xml);
 			if (decl) xml = xml.replace(decl,'');
-			if (ignoreWhitespace) xml = trimXMLWhitespace( xml) ;
+			if (ignoreWhitespace) xml = xml.trim();
 			//various node types not supported directly
 			//when parsing, always wrap (e4x ref p34, 'Semantics' of e4x-Ecma-357.pdf)
 			//custom: support alternate default xml namespace when parsing:
@@ -917,7 +914,12 @@ package
 					child = xmlFromStringable(child);
 				}
 			}
-			
+			if (child is XML  && (child as XML).getNodeRef() == ATTRIBUTE){
+				//convert to text node
+				var xml:XML= new XML();
+				xml._value = child.toString();
+				child = xml;
+			}
 			appendChildInternal(child);
 			//normalize seems not correct here:
 			//normalize();
@@ -3067,7 +3069,7 @@ package
 			{
 				if(prettyPrinting)
 				{
-					var v:String = trimXMLWhitespace(_value);
+					var v:String = (_value+'').trim();
 					if (v.indexOf('<![CDATA[') == 0) {
 						return indent + v;
 					}
diff --git a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
index d4663a5..3938c8e 100644
--- a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
+++ b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterGeneralTest.as
@@ -156,7 +156,30 @@ package flexUnitTests.xml
             assertEquals( xml3.foo.@boo,'boo', 'xml3.foo.@boo should be "boo"');
 
         }
-        
+
+        [Test]
+        public function testWhitespaceVariants():void{
+            XML.ignoreWhitespace = false;
+
+            var test:XML = new XML("    test   \n ");
+            assertEquals(test.toString().length,13, 'unexpected length')
+            XML.ignoreWhitespace = true;
+            test = new XML("    test   \n ");
+            assertEquals(test.toString().length,4, 'unexpected length')
+
+            XML.ignoreWhitespace = false;
+            var xml1:XML = new XML('<mynode red="value1"\r\n green="value2" blue="value3" \r\nyellow="value4" />');
+            assertEquals(xml1.toXMLString().length,67, 'unexpected length');
+            XML.ignoreWhitespace = true;
+            xml1 = new XML('<mynode red="value1"\r\n green="value2" blue="value3" \r\nyellow="value4" />');
+            assertEquals(xml1.toXMLString().length,67, 'unexpected length');
+            XML.ignoreWhitespace = false;
+            xml1 = new XML('    \r\n<mynode red="value1"\r\n green="value2" blue="value3" \r\nyellow="value4" />\r\n');
+            assertEquals(xml1.toXMLString().length,67, 'unexpected length');
+            XML.ignoreWhitespace = true;
+            xml1 = new XML('    \r\n<mynode red="value1"\r\n green="value2" blue="value3" \r\nyellow="value4" />\r\n');
+            assertEquals(xml1.toXMLString().length,67, 'unexpected length');
+        }
        
         
         [Test]