quintodrome/core
Deluan Quintão cc3cca6077
fix(scanner): handle cross-library relative paths in playlists (#4659)
* fix: handle cross-library relative paths in playlists

Playlists can now reference songs in other libraries using relative paths.
Previously, relative paths like '../Songs/abc.mp3' would not resolve correctly
when pointing to files in a different library than the playlist file.

The fix resolves relative paths to absolute paths first, then checks which
library they belong to using the library regex. This allows playlists to
reference files across library boundaries while maintaining backward
compatibility with existing single-library relative paths.

Fixes #4617

* fix: enhance playlist path normalization for cross-library support

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor: improve handling of relative paths in playlists for cross-library compatibility

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: ensure longest library path matches first to resolve prefix conflicts in playlists

Signed-off-by: Deluan <deluan@navidrome.org>

* test: refactor tests isolation

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: enhance handling of library-qualified paths and improve cross-library playlist support

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor: simplify mocks

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: lint

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: improve path resolution for cross-library playlists and enhance error handling

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor: remove unnecessary path validation fallback

Remove validatePathInLibrary function and its fallback logic in
resolveRelativePath. The library matcher should always find the correct
library, including the playlist's own library. If this fails, we now
return an invalid resolution instead of attempting a fallback validation.

This simplifies the code by removing redundant validation logic that
was masking test setup issues. Also fixes test mock configuration to
properly set up library paths that match folder LibraryPath values.

* refactor: consolidate path resolution logic

Collapse resolveRelativePath and resolveAbsolutePath into a unified
resolvePath function, extracting common library matching logic into a
new findInLibraries helper method.

This eliminates duplicate code (~20 lines) while maintaining clear
separation of concerns: resolvePath handles path normalization
(relative vs absolute), and findInLibraries handles library matching.

Update tests to call resolvePath directly with appropriate parameters,
maintaining full test coverage for both absolute and relative path
scenarios.

Signed-off-by: Deluan <deluan@navidrome.org>

* docs: add FindByPaths comment

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: enhance Unicode normalization for path comparisons in playlists. Fixes 4663

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
2025-12-06 12:05:38 -05:00
..
agents fix(server): Lastfm.ScrobbleFirstArtistOnly also only scrobbles the first artist of the album (#4762) 2025-12-03 15:55:25 -05:00
artwork fix(server): prioritize artist base image filenames over numeric suffixes and add tests for sorting 2025-11-14 13:15:50 -05:00
auth fix: retry insights collection when no admin user available (#4746) 2025-11-28 19:38:28 -05:00
external feat: make Unicode handling in external API calls configurable (#4277) 2025-12-02 13:08:30 -05:00
ffmpeg feat: add configurable transcoding cancellation (#4411) 2025-12-01 17:33:53 -05:00
lyrics fix: handle UTF BOM in lyrics and playlist files (#4637) 2025-10-31 09:07:23 -04:00
metrics fix(insights): add Parallels Shared Folders filesystem type to fsTypeMap 2025-12-02 17:00:13 -05:00
playback test: fix mpv tests on systems without /bin/bash installed - 4301 (#4302) 2025-07-02 21:55:55 -04:00
scrobbler feat(server): track scrobble/linstens history (#4770) 2025-12-06 11:07:18 -05:00
storage fix: improve URL path handling in local storage for special characters (#4378) 2025-07-23 20:46:47 -04:00
archiver.go feat(server): add M3U file to downloaded playlist 2025-05-27 20:13:37 -04:00
archiver_test.go feat(server): add M3U file to downloaded playlist 2025-05-27 20:13:37 -04:00
common.go feat(bfr): Big Refactor: new scanner, lots of new fields and tags, improvements and DB schema changes (#2709) 2025-02-19 20:35:17 -05:00
common_test.go test: add tests for userName and AbsolutePath in core/common.go 2025-04-18 11:53:47 -04:00
core_suite_test.go Rename log.LevelCritical to log.LevelFatal 2022-12-21 14:53:36 -05:00
inspect.go feat(bfr): Big Refactor: new scanner, lots of new fields and tags, improvements and DB schema changes (#2709) 2025-02-19 20:35:17 -05:00
library.go feat(scanner): implement selective folder scanning and file system watcher improvements (#4674) 2025-11-14 22:15:43 -05:00
library_test.go feat(scanner): implement selective folder scanning and file system watcher improvements (#4674) 2025-11-14 22:15:43 -05:00
maintenance.go fix(scanner): specify exact table to use for missing mediafile filter (#4689) 2025-11-16 12:54:28 -05:00
maintenance_test.go feat(scanner): implement selective folder scanning and file system watcher improvements (#4674) 2025-11-14 22:15:43 -05:00
media_streamer.go feat: add configurable transcoding cancellation (#4411) 2025-12-01 17:33:53 -05:00
media_streamer_Internal_test.go fix: forcing transcoding when client does not specify transcoding options (#3455) 2024-11-05 20:39:05 -05:00
media_streamer_test.go Add support for timeOffset in /stream endpoint 2023-12-02 13:10:36 -05:00
mock_library_service.go feat: Multi-library support (#4181) 2025-07-18 18:41:12 -04:00
players.go feat(server): group Subsonic config options together 2025-03-05 12:29:30 -08:00
players_test.go Use userId in player, other fixes (#3182) 2024-08-03 13:37:21 -04:00
playlists.go fix(scanner): handle cross-library relative paths in playlists (#4659) 2025-12-06 12:05:38 -05:00
playlists_internal_test.go fix(scanner): handle cross-library relative paths in playlists (#4659) 2025-12-06 12:05:38 -05:00
playlists_test.go fix(scanner): handle cross-library relative paths in playlists (#4659) 2025-12-06 12:05:38 -05:00
share.go refactor: extract TruncateRunes function for safe string truncation with suffix 2025-11-06 14:27:38 -05:00
share_test.go refactor: extract TruncateRunes function for safe string truncation with suffix 2025-11-06 14:27:38 -05:00
wire_providers.go fix: album statistics not updating after deleting missing files (#4668) 2025-11-08 20:11:00 -05:00