Skip to content

An open-source cross-platform alternative to AirDrop

fix: avoid adding a trailing dot when renaming files without an extension

ShlomoCode80816a3d58f0
diff --git a/app/assets/CHANGELOG.md b/app/assets/CHANGELOG.md
index bd1edf31..e2a45f90 100644
--- a/app/assets/CHANGELOG.md
+++ b/app/assets/CHANGELOG.md
@@ -1,5 +1,6 @@
## Unreleased
+- fix: avoid adding a trailing dot when renaming files without an extension (@ShlomoCode)
- fix(macos): file sharing via Share Extension doesn't work in DMG builds (@ShlomoCode, @vdmkotai)
- fix: show the real error when a file cannot be read while sending, instead of transferring it as an empty file (@leopalmieri-spec)
diff --git a/app/test/unit/util/file_path_helper_test.dart b/app/test/unit/util/file_path_helper_test.dart
index a04e7917..99e7e9d4 100644
--- a/app/test/unit/util/file_path_helper_test.dart
+++ b/app/test/unit/util/file_path_helper_test.dart
@@ -2,6 +2,14 @@ import 'package:localsend_isolates/util/file_path_helper.dart';
import 'package:test/test.dart';
void main() {
+ test('rename a file without an extension does not add a trailing dot', () {
+ expect('README'.withFileNameKeepExtension('renamed'), 'renamed');
+ });
+
+ test('rename a file preserves its extension', () {
+ expect('photo.jpg'.withFileNameKeepExtension('renamed'), 'renamed.jpg');
+ });
+
test('fileName with counter', () async {
expect('myFile'.withCount(1), 'myFile (1)');
expect('myFile (1)'.withCount(2), 'myFile (2)');
diff --git a/packages/localsend_isolates/lib/util/file_path_helper.dart b/packages/localsend_isolates/lib/util/file_path_helper.dart
index aee1b161..a6513cef 100644
--- a/packages/localsend_isolates/lib/util/file_path_helper.dart
+++ b/packages/localsend_isolates/lib/util/file_path_helper.dart
@@ -18,7 +18,7 @@ extension FilePathStringExt on String {
}
String withFileNameKeepExtension(String fileNameWithoutExt) {
- return '$fileNameWithoutExt.$extension';
+ return fileNameWithoutExt.withExtension(extension);
}
String withExtension(String ext) {