Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty value fix #60

Merged
merged 2 commits into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/xml
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def main():
##################################################################
# Is the xpath target an attribute selector?
# Yes: Set the attribute, exit
if module.params['value']:
if module.params['value'] is not None:
set_target(x, xpath, namespaces, attribute, value, module)

######################################################################
Expand Down
14 changes: 14 additions & 0 deletions tests/results/test-set-element-value-empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='UTF-8'?>
<business type="bar">
<name>Tasty Beverage Co.</name>
<beers>
<beer>Rochefort 10</beer>
<beer>St. Bernardus Abbot 12</beer>
<beer>Schlitz</beer>
</beers>
<rating subjective="true">10</rating>
<website>
<mobilefriendly/>
<address></address>
</website>
</business>
12 changes: 12 additions & 0 deletions tests/test-set-element-value-empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Setup test fixture
copy: src=fixtures/ansible-xml-beers.xml dest=/tmp/ansible-xml-beers.xml

- name: Set /business/website/address to empty string.
xml:
file: /tmp/ansible-xml-beers.xml
xpath: /business/website/address
value: ''

- name: Test expected result
command: diff results/test-set-element-value-empty.xml /tmp/ansible-xml-beers.xml
1 change: 1 addition & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- include: test-set-attribute-value.yml
- include: test-set-children-elements.yml
- include: test-set-element-value.yml
- include: test-set-element-value-empty.yml
- include: test-pretty-print.yml
- include: test-add-namespaced-children-elements.yml
- include: test-remove-namespaced-attribute.yml
Expand Down