Bug 47381 - XmlProperty doesn't allow propertvalues with only space(s)
Summary: XmlProperty doesn't allow propertvalues with only space(s)
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.7.1
Hardware: PC Windows Server 2003
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2009-06-17 04:28 UTC by Gilbert Rebhan
Modified: 2009-07-30 07:03 UTC (History)
0 users



Attachments
XmlProperty.java.diff.txt (442 bytes, patch)
2009-06-17 04:28 UTC, Gilbert Rebhan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gilbert Rebhan 2009-06-17 04:28:10 UTC
Created attachment 23823 [details]
XmlProperty.java.diff.txt

Discovered a difference related to the handling of txtproperties and xmlproperties after upgrading from ant 1.6.5 to ant 1.7.1

**Test 1**

* props.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <xmlkey></xmlkey>
  <xmlfoo>bar</xmlfoo>
</root>

* props.txt
txtfoo=bar
txtkey=

*TestScript
<project name="foobar" default="main" basedir=".">

  <!-- // Taskdefs -->
  <!-- Import AntContrib -->
  <taskdef resource="net/sf/antcontrib/antlib.xml" />
  <!-- Taskdefs // -->

  <!-- // Properties -->
  <property file="props.txt" />
  <xmlproperty file="props.xml" keeproot="false" />
  <!-- Properties // -->

  <target name="main">

    <echo>${ant.version}</echo>
    <echo>$${xmlkey} == ${xmlkey}</echo>
    <echo>$${txtkey} == ${txtkey}</echo>

    <if>
      <isset property="xmlkey" />
      <then>
        <echo>xmlkey set</echo>
      </then>
      <else>
        <echo>xmlkey not set</echo>
      </else>
    </if>

    <if>
      <isset property="txtkey" />
      <then>
        <echo>txtkey set</echo>
      </then>
      <else>
        <echo>txtkey not set</echo>
      </else>
    </if>

  </target>
</project>


*Output

[echo] Apache Ant version 1.6.5 compiled on June 2 2005
[echo] ${xmlkey} == ${xmlkey}
[echo] ${txtkey} == 
[echo] xmlkey not set
[echo] txtkey set

[echo] Apache Ant version 1.7.0 compiled on December 13 2006
[echo] ${xmlkey} == 
[echo] ${txtkey} == 
[echo] xmlkey set
[echo] txtkey set

[echo] Apache Ant version 1.7.1 compiled on June 27 2008
[echo] ${xmlkey} == 
[echo] ${txtkey} == 
[echo] xmlkey set
[echo] txtkey set

the different handling of empty txt and xml properties seems
to be fixed in conjunction with Bug 26286 - XmlProperty: empty element semantic problems 

but Test 2 shows another problem when xmlpropertyfile contains a node which has only
1 or more spaces, which is no problem in a txtpropertyfile

** Test 2 **

* props.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <xmlkey> </xmlkey>
  <xmlfoo>bar</xmlfoo>
</root>

* props.txt
txtfoo=bar
txtkey=*blank*

*Output

[echo] Apache Ant version 1.6.5 compiled on June 2 2005
[echo] ${xmlkey} == ${xmlkey}
[echo] ${txtkey} == 
[echo] xmlkey not set
[echo] txtkey set

[echo] Apache Ant version 1.7.0 compiled on December 13 2006
[echo] ${xmlkey} == ${xmlkey}
[echo] ${txtkey} == 
[echo] xmlkey not set
[echo] txtkey set

[echo] Apache Ant version 1.7.1 compiled on June 27 2008
[echo] ${xmlkey} == ${xmlkey}
[echo] ${txtkey} == 
[echo] xmlkey not set
[echo] txtkey set

which is wrong, as value of xmlkey is also = " " like value of txtkey

Fixed line 469 in org/apache/tools/taskdefs/XmlProperty

<   if (nodeText.trim().length() != 0 || emptyNode) {
---
>   if (nodeText.trim().length() >= 0 || emptyNode) {

and it works as expected =

[echo] Apache Ant version 1.7.1 compiled on June 27 2008
[echo] ${xmlkey} == 
[echo] ${txtkey} == 
[echo] xmlkey set
[echo] txtkey set
Comment 1 Gilbert Rebhan 2009-06-17 13:45:49 UTC
just checked on my private machine - OpenSUSE 11.1/64bit
with jdk 1.5.0_18 and jdk 1.6.0_13 and the same propertyfiles,
means <xmlkey> <xmlkey/> and txtkey=*blank*
but the patch has no impact, still the same output !?

Using a " " property may not be of practical importance, but the
behaviour should be the same for txtproperty and xmlproperty,
it is, but diametrical =

on my LinuxBox (jdk 5 +6, the same behavior already with ant 1.6.5)
[echo] ${xmlkey} == ${xmlkey}
[echo] ${txtkey} == ${txtkey}
[echo] xmlkey not set
[echo] txtkey not set

and on Windows and AIX (jdk 5 + 6)
[echo] ${xmlkey} ==
[echo] ${txtkey} ==
[echo] xmlkey set
[echo] txtkey set

maybe a 32bit <> 64bit issue ?
Right now i have no 32bit Linux around to check ..

Can someone confirm my investigations ?