sanitize file names

This commit is contained in:
Bnyro 2022-09-18 17:14:09 +02:00
parent 0e24a0981b
commit e7c4040c20
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,8 @@
package com.github.libretube.extensions
/**
* Replace file name specific chars
*/
fun String.sanitize(): String {
return this.replace("[^a-zA-Z0-9\\._]+", "_")
}

View File

@ -18,6 +18,7 @@ import com.github.libretube.constants.DOWNLOAD_FAILURE_NOTIFICATION_ID
import com.github.libretube.constants.DOWNLOAD_SUCCESS_NOTIFICATION_ID import com.github.libretube.constants.DOWNLOAD_SUCCESS_NOTIFICATION_ID
import com.github.libretube.constants.DownloadType import com.github.libretube.constants.DownloadType
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.sanitize
import com.github.libretube.util.DownloadHelper import com.github.libretube.util.DownloadHelper
import java.io.File import java.io.File
@ -37,7 +38,7 @@ class DownloadService : Service() {
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
videoName = intent?.getStringExtra("videoName")!! videoName = intent?.getStringExtra("videoName")!!.sanitize()
videoUrl = intent.getStringExtra("videoUrl")!! videoUrl = intent.getStringExtra("videoUrl")!!
audioUrl = intent.getStringExtra("audioUrl")!! audioUrl = intent.getStringExtra("audioUrl")!!