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

harbs 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 fe5f585f14 Fixed valueOf when it's supposed to be empty strings
     new ec545020fe Merge branch 'develop' of 
https://github.com/apache/royale-asjs into develop
fe5f585f14 is described below

commit fe5f585f14d1218675801ffa791713d480a8080e
Author: Harbs <[email protected]>
AuthorDate: Mon Jul 4 15:30:48 2022 +0300

    Fixed valueOf when it's supposed to be empty strings
---
 frameworks/projects/XML/src/main/royale/XMLList.as | 31 +++++++++++++++-------
 .../flexUnitTests/xml/XMLTesterStringifyTest.as    |  6 ++++-
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/frameworks/projects/XML/src/main/royale/XMLList.as 
b/frameworks/projects/XML/src/main/royale/XMLList.as
index 6900505f9c..cdd907ea33 100644
--- a/frameworks/projects/XML/src/main/royale/XMLList.as
+++ b/frameworks/projects/XML/src/main/royale/XMLList.as
@@ -394,8 +394,14 @@ package
                 */
                public function child(propertyName:Object):XMLList
                {
+                       if(isSingle())
+                               return _xmlArray[0].child(propertyName);
+
                        var retVal:XMLList = new XMLList();
                        retVal.targetProperty = propertyName.toString();
+                       if(isEmpty())
+                               retVal.targetObject = this;
+
                        var propNum:Number = parseInt(propertyName,10);
                        if(propNum.toString() == propertyName)
                        {
@@ -406,12 +412,6 @@ package
                                }
                                return retVal;
                        }
-                       if(isEmpty())
-                       {
-                               retVal.targetObject = this;
-                       }
-                       if(isSingle())
-                               return _xmlArray[0].child(propertyName);
                        var len:int = _xmlArray.length;
                        for (var i:int=0;i<len;i++)
                        {
@@ -1295,6 +1295,9 @@ package
                 */
                public function text():XMLList
                {
+                       if(isSingle())
+                               return _xmlArray[0].text();
+
                        var retVal:XMLList = new XMLList();
                        var len:int = _xmlArray.length;
                        for (var i:int=0;i<len;i++)
@@ -1384,14 +1387,24 @@ package
                
                /**
                 * Returns the XMLList object.
-                * 
-                * @return 
+                * @royaleignorecoercion XML
+                * @royaleignorecoercion QName
                 * 
                 */
                override public function valueOf():*
                {
                        if(isEmpty())
-                               return undefined;
+                       {
+                               var target:XML = targetObject;
+                               if(!target)
+                                       return undefined;
+                               // return undefined for undefined children and 
attributes
+                               var targetProp:QName = targetProperty;
+                               if(targetProp)
+                                       return undefined;
+                               // If there's no target property, valueOf on 
the target XML should be called
+                               return target.valueOf();
+                       }
                        if(isSingle())
                                return _xmlArray[0].valueOf();
 
diff --git 
a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterStringifyTest.as
 
b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterStringifyTest.as
index b587c18d8b..016cc47793 100644
--- 
a/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterStringifyTest.as
+++ 
b/frameworks/projects/XML/src/test/royale/flexUnitTests/xml/XMLTesterStringifyTest.as
@@ -307,7 +307,11 @@ package flexUnitTests.xml
             assertTrue( outString.length == expected.length, 'unexpected 
toString result');
         }
         
-        
+        [Test]
+        public function emptyStringify():void{
+            var xml:XML = <Foo><Baz/></Foo>;
+            assertEquals("" + xml.Baz.text(), "","An empty node should return 
an empty string");
+        }
         [Test]
         public function testCDATA():void{
             var script:XML = <script>   <![CDATA[private function 
onStylesLoaded(ev:Event):void {currentState = "normal";facade = 
ApplicationFacade.getInstance();facade.notifyObservers(new 
Notification(ApplicationFacade.CMD_STARTUP, this));}  ]]>  </script>;

Reply via email to