Skip to content

Commit

Permalink
xml: don't parse ADM elements outside audioFormatExtended
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjnixon committed Jul 27, 2024
1 parent a04e287 commit 6c5f008
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
- Padding after data chunks in bw64 files was not written, and this error was silently ignored in the reader. This can be fixed with the new `ear-utils rewrite` command.
- Mutable default parameters in ADMBuilder could cause unexpected extra blocks to be added when this was used from other programs.
- ADM elements outside the `audioFormatExtended` were parsed, causing errors for some files containing non-standard ADM data.

### Changed
- Added a warning for audioBlockFormats which have a duration but no rtime; previously these were fixed silently. See [#54].
Expand Down
10 changes: 10 additions & 0 deletions ear/fileio/adm/test/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,3 +1637,13 @@ def test_defaults(version):
with open(defaults_file, "w") as f:
f.write(xml_str)
pytest.skip("generated defaults file")


def test_ignore_outside_audioFormatExtended(base):
"""check that ADM-defined objects are only found in audioFormatExtended"""
[apr] = base.xml.xpath("//adm:audioProgramme", namespaces=nsmap)
adm = base.adm_after_mods(
add_children("//adm:format", E.notAudioFormatExtended(deepcopy(apr)))
)

assert len(adm.audioProgrammes) == 1
4 changes: 2 additions & 2 deletions ear/fileio/adm/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ def parse_adm_elements(self, adm, element, common_definitions=False):
for element_t in self.main_elements:
parse_func = element_t.handler.parse

for sub_element in xpath(element, "//{ns}" + element_t.name):
for sub_element in xpath(element, ".//{ns}" + element_t.name):
adm_element = parse_func(sub_element)

if common_definitions:
Expand Down Expand Up @@ -2025,7 +2025,7 @@ def default_get_main_elements_handler(version: Version) -> MainElementHandler:

def find_audioFormatExtended(element: lxml.etree._Element):
"""find the audioFormatExtended tag"""
afe_elements = list(xpath(element, "//{ns}audioFormatExtended"))
afe_elements = list(xpath(element, ".//{ns}audioFormatExtended"))
if len(afe_elements) == 0:
raise ValueError("no audioFormatExtended elements found")
elif len(afe_elements) > 1:
Expand Down

0 comments on commit 6c5f008

Please sign in to comment.