-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing File paths with special characters. (#2601)
* Fix parsing File paths with special characters. * Fix PathMapper as well. * Fix test.
- Loading branch information
1 parent
7a6ad60
commit cbef364
Showing
10 changed files
with
179 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -993,6 +993,7 @@ final fun coil3.size/Size(kotlin/Int, coil3.size/Dimension): coil3.size/Size // | |
final fun coil3.size/Size(kotlin/Int, kotlin/Int): coil3.size/Size // coil3.size/Size|Size(kotlin.Int;kotlin.Int){}[0] | ||
final fun coil3.size/SizeResolver(coil3.size/Size): coil3.size/SizeResolver // coil3.size/SizeResolver|SizeResolver(coil3.size.Size){}[0] | ||
final fun coil3/ImageLoader(coil3/PlatformContext): coil3/ImageLoader // coil3/ImageLoader|ImageLoader(coil3.PlatformContext){}[0] | ||
final fun coil3/Uri(kotlin/String? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/String = ...): coil3/Uri // coil3/Uri|Uri(kotlin.String?;kotlin.String?;kotlin.String?;kotlin.String?;kotlin.String?;kotlin.String){}[0] | ||
final inline fun (coil3.size/Dimension).coil3.size/pxOrElse(kotlin/Function0<kotlin/Int>): kotlin/Int // coil3.size/pxOrElse|[email protected](kotlin.Function0<kotlin.Int>){}[0] | ||
final inline fun (coil3.util/IntPair).coil3.util/component1(): kotlin/Int // coil3.util/component1|[email protected](){}[0] | ||
final inline fun (coil3.util/IntPair).coil3.util/component2(): kotlin/Int // coil3.util/component2|[email protected](){}[0] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
coil-core/src/androidInstrumentedTest/kotlin/coil3/fetch/FileFetcherTest.kt
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
coil-core/src/androidInstrumentedTest/kotlin/coil3/fetch/FileUriFetcherTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package coil3.fetch | ||
|
||
import coil3.ImageLoader | ||
import coil3.request.Options | ||
import coil3.size.Size | ||
import coil3.test.utils.context | ||
import coil3.test.utils.copyAssetToFile | ||
import coil3.toUri | ||
import coil3.util.ASSET_FILE_PATH_ROOT | ||
import coil3.util.SCHEME_FILE | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertNull | ||
import kotlinx.coroutines.test.runTest | ||
import okio.Path.Companion.toPath | ||
import org.junit.Test | ||
|
||
class FileUriFetcherTest { | ||
private val fetcherFactory = FileUriFetcher.Factory() | ||
|
||
@Test | ||
fun basic() = runTest { | ||
val file = "$SCHEME_FILE://${context.copyAssetToFile("normal.jpg")}".toUri() | ||
val options = Options(context, size = Size(100, 100)) | ||
val fetcher = fetcherFactory.create(file, options, ImageLoader(context)) | ||
|
||
assertNotNull(fetcher) | ||
|
||
val result = fetcher.fetch() | ||
|
||
assertIs<SourceFetchResult>(result) | ||
assertEquals("image/jpeg", result.mimeType) | ||
assertNotNull(result.source.file()) | ||
} | ||
|
||
@Test | ||
fun doesNotHandleAssetUris() { | ||
val uri = "$SCHEME_FILE:///$ASSET_FILE_PATH_ROOT/asset.jpg".toUri() | ||
assertNull(fetcherFactory.create(uri, Options(context), ImageLoader(context))) | ||
} | ||
|
||
@Test | ||
fun doesNotHandleGenericString() { | ||
val uri = "generic_string".toUri() | ||
assertNull(fetcherFactory.create(uri, Options(context), ImageLoader(context))) | ||
} | ||
|
||
/** Regression test: https://github.com/coil-kt/coil/issues/1513 */ | ||
@Test | ||
fun ignoresAfterPathCorrectly() = runTest { | ||
val uri = "$SCHEME_FILE:///sdcard/file.jpg?query=value&query2=value#fragment".toUri() | ||
val fetcher = assertNotNull(fetcherFactory.create(uri, Options(context), ImageLoader(context))) | ||
val result = assertIs<SourceFetchResult>(fetcher.fetch()) | ||
assertEquals("/sdcard/file.jpg".toPath(), result.source.file()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
coil-core/src/jvmCommonTest/kotlin/coil3/map/FileMapperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package coil3.map | ||
|
||
import coil3.request.Options | ||
import coil3.test.utils.RobolectricTest | ||
import coil3.test.utils.context | ||
import coil3.toUri | ||
import coil3.util.SCHEME_FILE | ||
import java.io.File | ||
import kotlin.test.assertEquals | ||
import org.junit.Test | ||
|
||
class FileMapperTest : RobolectricTest() { | ||
private val mapper = FileMapper() | ||
|
||
@Test | ||
fun basic() { | ||
val file = File("/path/to/file") | ||
val uri = "$SCHEME_FILE:/path/to/file".toUri() | ||
assertEquals(uri, mapper.map(file, Options(context))) | ||
} | ||
|
||
/** Regression test: https://github.com/coil-kt/coil/issues/1344 */ | ||
@Test | ||
fun parsesPoundCharacterCorrectly() { | ||
val path = "/sdcard/fi#le.jpg" | ||
val file = File("/sdcard/fi#le.jpg") | ||
assertEquals(path, mapper.map(file, Options(context)).path) | ||
} | ||
|
||
/** Regression test: https://github.com/coil-kt/coil/issues/1513 */ | ||
@Test | ||
fun decodesEncodedPath() { | ||
val path = "/sdcard/Some+File.jpg" | ||
val uri = "$SCHEME_FILE:$path".toUri() | ||
val file = File(path) | ||
assertEquals(uri, mapper.map(file, Options(context))) | ||
} | ||
} |