CreateMode.REPLACE not respected on malformed input
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Parti da MediaStoreCompat.createDownload, riproduci il problema con un nome di FileDescription contenente "?" e CreateMode.REPLACE, quindi ispeziona il nome del file di archiviazione restituito. Determina il comportamento previsto quando l’OS rinomina un input malformato; il lavoro è completato quando chiamate ripetute non creano più "hello_(1)" in modo imprevisto e il comportamento scelto è coperto o documentato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
CreateMode.REPLACE not respected on malformed input
When testing MediaStoreCompat.createDownload I found a bug caused by the OS renaming the name when it has invalid input.
Assume you have some regular function to create a file.
fun testDuplicate(context : Context) {
val file = MediaStoreCompat.createDownload(
context = context,
file = FileDescription(
name = "hello",
"test",
mimeType = "text/plain"
),
mode = CreateMode.REPLACE
)?.toStorageFile(context)
file?.openOutputStream()?.writer()?.use { writer ->
writer.write("Hello World!")
writer.flush()
}
}
This just creates a file named "hello.txt" with the content "Hello World!". And if called twice it replaces the file.
testDuplicate(context)
testDuplicate(context)
-> only 1 file
This is expected behavior, and everything is fine.
However if I now choose the name = "hello?" it creates the file fine, but the OS renames it to hello_, therefore the subsequent call to testDuplicate does not replace "hello_" because it is searching for "hello?" and therefore creates a new file called "hello_(1)".
The expected behavior is to either fail or replace the file named "hello_". However the current implementation creates another file even with the mode CreateMode.REPLACE.
This issue is fixed if the createDownload function also sanitized the file name like the os with e.g. .replace("?","_"), however I get that this is a wonky solution. I think it is sane to either document this as an issue, sanitize the filename, or even detect the creation of the wrong file name.
- Lingua principale
- Kotlin
- Stelle
- 867
- Fork
- 103
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di anggrayudi/SimpleStorage
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
anggrayudi/SimpleStorage#160 ·
-
bug unreproducible
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
anggrayudi/SimpleStorage#107 · 10 commenti ·
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
anggrayudi/SimpleStorage#106 · 1 commento ·
-
bug wontfix
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
anggrayudi/SimpleStorage#103 · 7 commenti ·
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
anggrayudi/SimpleStorage#94 · 8 commenti ·
Tutte le issue di anggrayudi/SimpleStorage
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PostHog/posthog-kmp#100 ·
I maintainer di solito rispondono entro 2 giorni
-
Feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
keiyoushi/extensions-source#20102 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
"Check mod" buttonApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
yairm210/Unciv#15803 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement triaged
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno