Skip to content

Commit

Permalink
fix '&' escape bug in XMLPlaylistParser
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Jul 25, 2024
1 parent 0083d47 commit ec50f65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/info/release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ Release History
The format is based on `Keep a Changelog <https://keepachangelog.com/en>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_


1.1.5
=====

Fixed
-----
* Bug in escaping of '&' characters when export :py:class:`.XAutoPF` playlists with the :py:class:`.XMLPlaylistParser`.
Was previously escaping multiple times when already escaped e.g. '&amp;' > '&amp;amp;'.
Now correctly skips already occurrences of '&'.


1.1.4
=====

Expand Down
6 changes: 4 additions & 2 deletions musify/libraries/local/playlist/xautopf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
The XAutoPF implementation of a :py:class:`LocalPlaylist`.
"""
import re
from collections.abc import Collection, Mapping, Sequence
from copy import deepcopy
from dataclasses import dataclass
Expand Down Expand Up @@ -513,12 +514,13 @@ def parse_exception_paths(
include_items = tuple(items_mapped[path] for path in matcher.include if path in items_mapped)
exclude_items = tuple(matched_mapped[path] for path in matcher.exclude if path in matched_mapped)

amp_pattern = re.compile('&(?!amp;)')
if len(include_items) > 0:
include_paths = self.path_mapper.unmap_many(include_items, check_existence=False)
self.xml_source["ExceptionsInclude"] = "|".join(include_paths).replace("&", "&amp;")
self.xml_source["ExceptionsInclude"] = amp_pattern.sub("&amp;", "|".join(include_paths))
if len(exclude_items) > 0:
exclude_paths = self.path_mapper.unmap_many(exclude_items, check_existence=False)
self.xml_source["Exceptions"] = "|".join(exclude_paths).replace("&", "&amp;")
self.xml_source["Exceptions"] = amp_pattern.sub("&amp;", "|".join(exclude_paths))

def get_limiter(self) -> ItemLimiter | None:
"""Initialise and return a :py:class:`ItemLimiter` object from loaded XML playlist data."""
Expand Down

0 comments on commit ec50f65

Please sign in to comment.