Skip to content

Commit

Permalink
Fix parsing paths containing # in FileUriMapper. (#1466)
Browse files Browse the repository at this point in the history
* Fix parsing paths containing # in FileUriMapper.

* Rename test.
  • Loading branch information
colinrtwhite committed Sep 19, 2022
1 parent a234e81 commit 822b5c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions coil-base/src/androidTest/java/coil/map/FileUriMapperTest.kt
Expand Up @@ -46,4 +46,11 @@ class FileUriMapperTest {
val uri = "generic_string".toUri()
assertNull(mapper.map(uri, Options(context)))
}

@Test
fun parsesPoundCharacterCorrectly() {
val path = "/sdcard/fi#le.jpg"
assertEquals(File(path), mapper.map(path.toUri(), Options(context)))
assertEquals(File(path), mapper.map("file://$path".toUri(), Options(context)))
}
}
3 changes: 2 additions & 1 deletion coil-base/src/main/java/coil/map/FileUriMapper.kt
Expand Up @@ -11,7 +11,8 @@ internal class FileUriMapper : Mapper<Uri, File> {

override fun map(data: Uri, options: Options): File? {
if (!isApplicable(data)) return null
return File(data.path!!)
val uri = if (data.scheme == null) data else data.buildUpon().scheme(null).build()
return File(uri.toString())
}

private fun isApplicable(data: Uri): Boolean {
Expand Down

0 comments on commit 822b5c1

Please sign in to comment.