fix(conversion): preserve Unicode SAF document names

This commit is contained in:
zarzet
2026-09-04 12:39:03 +07:00
parent a0aa99f24d
commit 4aba2926f8
4 changed files with 140 additions and 70 deletions
+62
View File
@@ -2,6 +2,68 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:spotiflac_android/utils/saf_display_path.dart';
void main() {
group('SAF document locations', () {
test('keeps Unicode and reserved filename characters decoded once', () {
final uri = Uri(
scheme: 'content',
host: 'com.android.externalstorage.documents',
pathSegments: const [
'tree',
'primary:Music',
'document',
'primary:Music/Like a Prayer (From “Deadpool & Wolverine”).alac',
],
).toString();
final location = resolveSafDocumentLocation(uri);
expect(location, isNotNull);
expect(
location!.treeUri,
'content://com.android.externalstorage.documents/tree/primary%3AMusic',
);
expect(location.relativeDir, isEmpty);
expect(
location.fileName,
'Like a Prayer (From “Deadpool & Wolverine”).alac',
);
});
test('preserves Unicode folders, emoji, and a literal percent sign', () {
final uri = Uri(
scheme: 'content',
host: 'com.android.externalstorage.documents',
pathSegments: const [
'tree',
'primary:Music/Beyoncé',
'document',
'primary:Music/Beyoncé/日本語/100% & 🎵.flac',
],
).toString();
final location = resolveSafDocumentLocation(uri);
expect(location, isNotNull);
expect(
location!.treeUri,
'content://com.android.externalstorage.documents/tree/'
'primary%3AMusic%2FBeyonc%C3%A9',
);
expect(location.relativeDir, '日本語');
expect(location.fileName, '100% & 🎵.flac');
});
test('rejects a document URI without writable tree context', () {
expect(
resolveSafDocumentLocation(
'content://com.android.providers.media.documents/'
'document/audio%3A12345',
),
isNull,
);
});
});
group('SAF display paths', () {
test('normalizes an external-storage document URI', () {
const uri =