Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing paths containing # in FileUriMapper. #1466

Merged
merged 2 commits into from Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was a breaking change for us as we were previously sending local image's uri, now uri.path works, you should have document this

}

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