From debbb0b59c7092ffeef5743d001b944e990fb8cf Mon Sep 17 00:00:00 2001 From: ersanin Date: Wed, 13 Nov 2024 16:37:40 +0300 Subject: [PATCH 1/2] ISSUE-675: sanitize filename in video recorder --- .../com/kaspersky/kaspresso/device/video/VideosImpl.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt index bdf99a2f9..60ea69fb4 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt @@ -12,7 +12,10 @@ class VideosImpl( ) : Videos { override fun record(tag: String) { - val videoFile: File = resourceFilesProvider.provideVideoFile(tag) + val sanitizedVideoName = tag + .replace("[/:\"*?<>|]+".toRegex(), "") + .replace(' ', '_') + val videoFile: File = resourceFilesProvider.provideVideoFile(sanitizedVideoName) videoRecorder.start(videoFile) } From b01fd581c105a3c01251cabf40274847d71cfaa6 Mon Sep 17 00:00:00 2001 From: ersanin Date: Tue, 26 Nov 2024 01:02:14 +0300 Subject: [PATCH 2/2] ISSUE-675: review reaction --- .../com/kaspersky/kaspresso/device/video/VideosImpl.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt index 60ea69fb4..0f7263c79 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/video/VideosImpl.kt @@ -12,9 +12,10 @@ class VideosImpl( ) : Videos { override fun record(tag: String) { - val sanitizedVideoName = tag - .replace("[/:\"*?<>|]+".toRegex(), "") - .replace(' ', '_') + val sanitizedVideoName = tag.replace("[/:\"*?<>|]+".toRegex(), "_") + if (tag != sanitizedVideoName) { + logger.d("Can't record video with name $tag since it contains one of the following special characters [/:\"*?<>|]. Changing the name to $sanitizedVideoName") + } val videoFile: File = resourceFilesProvider.provideVideoFile(sanitizedVideoName) videoRecorder.start(videoFile) }