mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Use System.Xml.XmlDocument.Load rather than Get-Content to avoid (#49206)
encoding errors when writing out XML removing executable bit refactor tests to handle sanity checking
This commit is contained in:
parent
9d62cbc2af
commit
5cb39d0d57
4 changed files with 62 additions and 8 deletions
2
changelogs/fragments/48471-win_xml-xml-parser.yaml
Normal file
2
changelogs/fragments/48471-win_xml-xml-parser.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- win_xml - use New-Object System.Xml.XmlDocument rather than Get-Content for parsing xml (https://github.com/ansible/ansible/issues/48471)
|
|
@ -107,9 +107,10 @@ If (-Not (Test-Path -Path $dest -PathType Leaf)){
|
|||
Fail-Json $result "Specified path $dest does not exist or is not a file."
|
||||
}
|
||||
|
||||
[xml]$xmlorig = $null
|
||||
$xmlorig = New-Object -TypeName System.Xml.XmlDocument
|
||||
$xmlorig.XmlResolver = $null
|
||||
Try {
|
||||
[xml]$xmlorig = Get-Content -Path $dest
|
||||
$xmlorig.Load($dest)
|
||||
}
|
||||
Catch {
|
||||
Fail-Json $result "Failed to parse file at '$dest' as an XML document: $($_.Exception.Message)"
|
||||
|
|
BIN
test/integration/targets/win_xml/files/plane.zip
Normal file
BIN
test/integration/targets/win_xml/files/plane.zip
Normal file
Binary file not shown.
|
@ -71,3 +71,54 @@
|
|||
assert:
|
||||
that:
|
||||
- not attribute_changed_result is changed
|
||||
|
||||
# This testing is for https://github.com/ansible/ansible/issues/48471
|
||||
# The issue was that an .xml with no encoding declaration, but a UTF8 BOM
|
||||
# with some UTF-8 characters was being written out with garbage characters.
|
||||
# The characters added by win_xml were not UTF-8 characters.
|
||||
|
||||
- name: copy test files (https://github.com/ansible/ansible/issues/48471)
|
||||
win_copy:
|
||||
src: plane.zip
|
||||
dest: "{{ win_output_dir }}\\plane.zip"
|
||||
|
||||
- name: unarchive the test files
|
||||
win_unzip:
|
||||
src: "{{ win_output_dir }}\\plane.zip"
|
||||
dest: "{{ win_output_dir }}\\"
|
||||
|
||||
- name: change a text value in a file with UTF8 BOM and armenian characters in the description
|
||||
win_xml:
|
||||
path: "{{ win_output_dir }}\\plane-utf8-bom-armenian-characters.xml"
|
||||
xpath: '/plane/year'
|
||||
type: text
|
||||
fragment: '1988'
|
||||
|
||||
- name: register the sha1 of the new file
|
||||
win_stat:
|
||||
path: "{{ win_output_dir }}\\plane-utf8-bom-armenian-characters.xml"
|
||||
get_checksum: yes
|
||||
register: sha1_checksum
|
||||
|
||||
- name: verify the checksum
|
||||
assert:
|
||||
that:
|
||||
- sha1_checksum.stat.checksum == 'e3e18c3066e1bfce9a5cf87c81353fa174440944'
|
||||
|
||||
- name: change a text value in a file with UTF-16 BE BOM and Chinese characters in the description
|
||||
win_xml:
|
||||
path: "{{ win_output_dir }}\\plane-utf16be-bom-chinese-characters.xml"
|
||||
xpath: '/plane/year'
|
||||
type: text
|
||||
fragment: '1988'
|
||||
|
||||
- name: register the sha1 of the new file
|
||||
win_stat:
|
||||
path: "{{ win_output_dir}}\\plane-utf16be-bom-chinese-characters.xml"
|
||||
get_checksum: yes
|
||||
register: sha1_checksum
|
||||
|
||||
- name: verify the checksum
|
||||
assert:
|
||||
that:
|
||||
- sha1_checksum.stat.checksum == 'de86f79b409383447cf4cf112b20af8ffffcfdbf'
|
||||
|
|
Loading…
Add table
Reference in a new issue