-
Notifications
You must be signed in to change notification settings - Fork 87
Closed
Description
require 'rexml'
xml = <<~XML
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
<file original="test.plist" source-language="en" datatype="plaintext" target-language="en">
<header>
<tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="8.3.3" build-num="8E3004b" />
</header>
<body>
<trans-unit id="test">
<source>test</source>
<target></target>
</trans-unit>
<trans-unit id="We're happy to see you">
<source>We're happy to see you</source>
<target></target>
</trans-unit>
</body>
</file>
</xliff>
XML
@doc = REXML::Document.new(xml)
REXML::XPath.first(@doc, '//trans-unit').attributes['id'] = "I'm here"
puts @doc.to_s<?xml version='1.0' encoding='UTF-8'?>
<xliff xsi:schemaLocation='urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd' version='1.2' xmlns='urn:oasis:names:tc:xliff:document:1.2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<file datatype='plaintext' original='test.plist' source-language='en' target-language='en'>
<header>
<tool build-num='8E3004b' tool-id='com.apple.dt.xcode' tool-name='Xcode' tool-version='8.3.3'/>
</header>
<body>
<trans-unit id='I'm here'>
<source>test</source>
<target/>
</trans-unit>
<trans-unit id='We're happy to see you'>
<source>We're happy to see you</source>
<target/>
</trans-unit>
</body>
</file>
</xliff>All good! ✅
When using {attribute_quote: :quote} to generate files with double quoted attributes, not editing anything there:
@doc = REXML::Document.new(xml, {attribute_quote: :quote})
puts @doc.to_s<?xml version='1.0' encoding='UTF-8'?>
<xliff xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<file datatype="plaintext" original="test.plist" source-language="en" target-language="en">
<header>
<tool build-num="8E3004b" tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="8.3.3"/>
</header>
<body>
<trans-unit id="test">
<source>test</source>
<target/>
</trans-unit>
<trans-unit id="We're happy to see you">
<source>We're happy to see you</source>
<target/>
</trans-unit>
</body>
</file>
</xliff>All good too! ✅
But if I edit a trans-unit:
@doc = REXML::Document.new(xml, {attribute_quote: :quote})
REXML::XPath.first(@doc, '//trans-unit').attributes['id'] = "I'm here"
puts @doc.to_s<?xml version='1.0' encoding='UTF-8'?>
<xliff xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<file datatype="plaintext" original="test.plist" source-language="en" target-language="en">
<header>
<tool build-num="8E3004b" tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="8.3.3"/>
</header>
<body>
<trans-unit id="I'm here">
<source>test</source>
<target/>
</trans-unit>
<trans-unit id="We're happy to see you">
<source>We're happy to see you</source>
<target/>
</trans-unit>
</body>
</file>
</xliff>(Note the <trans-unit id="I'm here">). It should be <trans-unit id="I'm here">. The element we edited has its quote incorrectly HTML-escaped, while the one we didn't edit is correctly unescaped.
It looks like editing an element makes it loose its context[:attribute_quote:].
Metadata
Metadata
Assignees
Labels
No labels