Highly Complete: Fix crash on paths containing URL escapes

In the event of local paths containing not just UTF-8 characters,
but also un-decoded URL percent sequences, which will end up double
encoded in the player, code which reverses percent encoding should
later re-apply it.

Apparently, this whole time, since the last code overhaul, the
URL encoding was being stripped, then the file opener was converting
these paths back into URLs without re-encoding, which didn't break
until someone played an album in a folder containing a partially
decoded UTF-8 sequence. Thanks, Zophar's Domain, and whoever ripped
the Golden Sun GSF set for finding this bug!

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-01-14 21:22:26 -08:00
parent 7e98a0398b
commit 838d5ca9f7

View file

@ -103,6 +103,7 @@ void *source_fopen(const char *path) {
id<CogSource> source;
if(![[psf_file_container instance] try_hint:[NSString stringWithUTF8String:path] source:&source]) {
NSString *urlString = [NSString stringWithUTF8String:path];
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLFragmentAllowedCharacterSet];
NSURL *url = [NSURL URLWithDataRepresentation:[urlString dataUsingEncoding:NSUTF8StringEncoding] relativeToURL:nil];
id audioSourceClass = NSClassFromString(@"AudioSource");