mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
[PR #11959/d87a8a16 backport][stable-11] xml: fail for non-string values (#12000)
* xml: fail for non-string `value`s (#11959)
* fix(xml): coerce boolean values to string with a warning
Fixes #7171
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(xml): add integration tests for boolean value handling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* changelog: add fragment for PR 11959
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* adjustments from review
* test(xml): update boolean-value integration tests to expect failure
Now that xml fails on non-string values, replace the old success-path
tests with failure assertions and add a positive test for quoted strings.
Remove the no-longer-needed result XML fixtures.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* adjustments from review
* fix(xml): correct boolean test assertions to match actual error message format
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
(cherry picked from commit d87a8a167f)
* Make Python 2.7 compatible.
Co-authored-by: Felix Fontein <felix@fontein.de>
* Fix typo.
* One more.
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
@@ -689,6 +689,16 @@ def set_target_inner(module, tree, xpath, namespaces, attribute, value):
|
||||
module.fail_json(msg="Xpath %s does not reference a node! tree is %s" %
|
||||
(xpath, etree.tostring(tree, pretty_print=True)))
|
||||
|
||||
if not isinstance(value, str):
|
||||
target = ("attribute '{attribute}' at xpath '{xpath}'" if attribute else "element text at xpath '{xpath}'").format(attribute=attribute, xpath=xpath)
|
||||
module.fail_json(
|
||||
msg=(
|
||||
"A non-string value {value!r} was parsed for {target}. ".format(value=value, target=target) +
|
||||
"YAML values for booleans, octals, floats may not yield the string you intended. "
|
||||
"""Quote the value to be explicit, like `value: "yes"`."""
|
||||
)
|
||||
)
|
||||
|
||||
for element in tree.xpath(xpath, namespaces=namespaces):
|
||||
if not attribute:
|
||||
changed = changed or (element.text != value)
|
||||
|
||||
Reference in New Issue
Block a user