Skip to content

Commit

Permalink
PICARD-2960: Config upgrade hook to sanitize dir separator replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Sep 1, 2024
1 parent 2c6052e commit e69dcb3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion picard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
PICARD_DISPLAY_NAME = "MusicBrainz Picard"
PICARD_APP_ID = "org.musicbrainz.Picard"
PICARD_DESKTOP_NAME = PICARD_APP_ID + ".desktop"
PICARD_VERSION = Version(3, 0, 0, 'dev', 4)
PICARD_VERSION = Version(3, 0, 0, 'dev', 5)


# optional build version
Expand Down
11 changes: 11 additions & 0 deletions picard/config_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
getmembers,
isfunction,
)
import os
import re
import sys

Expand All @@ -47,6 +48,7 @@
)
from picard.const.defaults import (
DEFAULT_FILE_NAMING_FORMAT,
DEFAULT_REPLACEMENT,
DEFAULT_SCRIPT_NAME,
)
from picard.const.sys import IS_FROZEN
Expand Down Expand Up @@ -550,6 +552,15 @@ def upgrade_to_v3_0_0dev4(config):
config.persist.remove('file_view_header_state')


def upgrade_to_v3_0_0dev5(config):
"""Ensure "replace_dir_separator" contains no directory separator"""
replace_dir_separator = config.setting['replace_dir_separator']
replace_dir_separator = replace_dir_separator.replace(os.sep, DEFAULT_REPLACEMENT)
if os.altsep:
replace_dir_separator = replace_dir_separator.replace(os.altsep, DEFAULT_REPLACEMENT)
config.setting['replace_dir_separator'] = replace_dir_separator


def rename_option(config, old_opt, new_opt, option_type, default):
_s = config.setting
if old_opt in _s:
Expand Down
14 changes: 14 additions & 0 deletions test/test_config_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import os

from PyQt6.QtCore import QByteArray

Expand Down Expand Up @@ -66,9 +67,11 @@
upgrade_to_v2_8_0dev2,
upgrade_to_v3_0_0dev3,
upgrade_to_v3_0_0dev4,
upgrade_to_v3_0_0dev5,
)
from picard.const.defaults import (
DEFAULT_FILE_NAMING_FORMAT,
DEFAULT_REPLACEMENT,
DEFAULT_SCRIPT_NAME,
)
from picard.util import unique_numbered_title
Expand Down Expand Up @@ -541,3 +544,14 @@ def test_upgrade_to_v3_0_0dev4(self):
upgrade_to_v3_0_0dev4(self.config)
self.assertEqual(b'', self.config.persist['album_view_header_state'])
self.assertEqual(b'', self.config.persist['file_view_header_state'])

def test_upgrade_to_v3_0_0dev5(self):
TextOption('setting', 'replace_dir_separator', DEFAULT_REPLACEMENT)
self.config.setting['replace_dir_separator'] = os.sep
upgrade_to_v3_0_0dev5(self.config)
self.assertEqual(DEFAULT_REPLACEMENT, self.config.setting['replace_dir_separator'])

if os.altsep:
self.config.setting['replace_dir_separator'] = os.altsep
upgrade_to_v3_0_0dev5(self.config)
self.assertEqual(DEFAULT_REPLACEMENT, self.config.setting['replace_dir_separator'])

0 comments on commit e69dcb3

Please sign in to comment.