Automattic / Automattic/xliff

Preserve namespace declarations and prefixes on Header round-trip

Open
#18 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
3
Forks
2
Avg merge
2h 46m
Merged PRs (30d)
3

Description

`Xliff::Header` models a header as an element name plus a flat attribute hash. Following #15 it preserves `xml:`-prefixed attributes (e.g. `xml:lang`), but namespace handling is otherwise incomplete:

- `Header.from_xml` reads the element name via `xml.name` (the *local* name), so a namespaced header element such as `` loses its prefix and round-trips as ``.
- For an attribute under a non-`xml:` prefix (e.g. ``), `from_xml` captures the key as `x:custom`, but `to_xml` re-emits `x:custom="v"` **without** an `xmlns:x` declaration — producing malformed XML (undefined namespace prefix) rather than valid output.

The predefined `xml:` prefix works because it needs no declaration; every other prefix breaks. Xcode's exports only use unprefixed `` attributes, so this isn't hit in the library's primary use case — but XLIFF permits vendor extension elements/attributes in ``, so another tool's file could trip it.

## Proposed fix

Capture the header element's `namespace_definitions` (and its own namespace) on parse and re-declare them on write, and preserve the element's qualified name — so any prefixed content round-trips as valid XML.

## Scope

Split out of the #15 review; related to the broader faithful-preservation work in #17. Until then the limitation is documented in the README's "Conformance and limitations" section.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading Xliff::Header.from_xml and to_xml, then review the README's "Conformance and limitations" section and the context from issues #15 and #17. Confirm the existing behavior with namespaced elements and attributes; done means a Header round-trip preserves qualified names and namespace declarations while producing valid XML.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.