Skip to content

Commit

Permalink
Merge pull request #1244 from yast/sw_11
Browse files Browse the repository at this point in the history
do not strip surrounding white space in CDATA XML elements (bsc#1195910)
  • Loading branch information
wfeldt authored Feb 17, 2022
2 parents 81558cb + 74b6f7a commit eed423e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
17 changes: 5 additions & 12 deletions library/xml/src/modules/XML.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,12 @@ def parse_node(node, result)
# we need just direct text under node. Can be splitted with another elements
# but remove whitespace only text
#
# Do NOT strip trailing white space in CDATA blocks. Maybe people put
# it intentionally there (bsc#1195910).
#
# But strip leading white space. This is useful to avoid problems with
# unexpected empty lines at the start of scripts.
#
# An example for this is the script section in this AutoYaST file from
# the official AutoYaST docs:
# https://doc.opensuse.org/projects/autoyast/#Profile-Format
# Do NOT strip surrounding white space in CDATA blocks (bsc#1195910).
# This restores the behavior prior to SLE15-SP3.
#
# See also #add_element.
text_nodes = node.xpath("text()")
text = text_nodes.map { |n| n.cdata? ? n.content.lstrip : n.content.strip }.join
text = text_nodes.map { |n| n.cdata? ? n.content : n.content.strip }.join

type = fetch_type(text, children, node)

Expand Down Expand Up @@ -314,9 +307,9 @@ def add_element(doc, metadata, parent, contents, parent_array: nil)
element = Nokogiri::XML::Node.new(key, doc)
case value
when ::String
# Write CDATA block if string ends with white space. This matches
# Write CDATA block if string has surrounding white space. This matches
# the stripping in #parse_node.
if value.match?(/\s\z/)
if value.match?(/\A\s|\s\z/)
element.add_child(doc.create_cdata(value))
else
element.content = value
Expand Down
10 changes: 5 additions & 5 deletions library/xml/test/xml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
expect(subject.YCPToXMLString("test", input)).to eq expected
end

it "creates no CDATA element if string starts with spaces" do
it "creates CDATA element if string starts with spaces" do
input = { "test" => " test", "lest" => "\nlest" }
expected = "<?xml version=\"1.0\"?>\n" \
"<!DOCTYPE test SYSTEM \"just_testing.dtd\">\n" \
"<test>\n" \
" <lest>\nlest</lest>\n" \
" <test> test</test>\n" \
" <lest><![CDATA[\nlest]]></lest>\n" \
" <test><![CDATA[ test]]></test>\n" \
"</test>\n"

expect(subject.YCPToXMLString("test", input)).to eq expected
Expand Down Expand Up @@ -343,13 +343,13 @@
expect(subject.XMLToYCPString(input)).to eq expected
end

it "strips spaces at the start of CDATA elements" do
it "preserves spaces at the start of CDATA elements" do
input = "<?xml version=\"1.0\"?>\n" \
"<test xmlns=\"http://www.suse.com/1.0/yast2ns\" xmlns:config=\"http://www.suse.com/1.0/configns\">\n" \
" <test><![CDATA[ foo]]></test>\n" \
" <lest><![CDATA[\nbar]]></lest>\n" \
"</test>\n"
expected = { "test" => "foo", "lest" => "bar" }
expected = { "test" => " foo", "lest" => "\nbar" }

expect(subject.XMLToYCPString(input)).to eq expected
end
Expand Down
6 changes: 6 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Feb 17 09:33:37 UTC 2022 - Steffen Winterfeldt <snwint@suse.com>

- do not strip surrounding white space in CDATA XML elements (bsc#1195910)
- 4.3.68

-------------------------------------------------------------------
Wed Feb 16 15:41:54 UTC 2022 - Steffen Winterfeldt <snwint@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.3.67
Version: 4.3.68

Release: 0
Summary: YaST2 Main Package
Expand Down

0 comments on commit eed423e

Please sign in to comment.