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 uri parse error in the Windows system. #2251

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Caij
Copy link

@Caij Caij commented May 12, 2024

Please run ./test.sh before submitting to ensure your pull request passes the automated checks.

@Caij
Copy link
Author

Caij commented May 12, 2024

Windows local path parse error. D:\test\relative\image.jpg

class Factory : Fetcher.Factory<Uri> {
        override fun create(
            data: Uri,
            options: Options,
            imageLoader: ImageLoader,
        ): Fetcher? {
            if (!isFileUri(data)) return null
            return FileUriFetcher(data, options)
        }
    }
internal fun isFileUri(uri: Uri): Boolean {
    return (uri.scheme == null || uri.scheme == SCHEME_FILE) &&
        uri.path != null &&
        !isAssetUri(uri)
}

Here the uri.path is empty, so the FileUriFetcher factory can't be found.

@Test
fun windows() {
val uri = "D:\\test\\relative\\image.jpg".toUri()
assertNull(uri.scheme)
Copy link
Member

Choose a reason for hiding this comment

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

Is it correct that scheme is null? Should it be D?

Copy link
Author

Choose a reason for hiding this comment

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

Is it correct that scheme is null? Should it be D?

I think D is the volume information, it should be part of the path.

@colinrtwhite
Copy link
Member

Thanks for taking a stab at this - unfortunately looks like the tests are failing with a StackOverflowError. You can run the tests locally using ./test.sh.

@Caij
Copy link
Author

Caij commented May 14, 2024

Thanks for taking a stab at this - unfortunately looks like the tests are failing with a StackOverflowError. You can run the tests locally using ./test.sh.

There was an error and I fixed it, and it has been submitted.

@colinrtwhite
Copy link
Member

Sorry for the delay on merging this. After thinking about this I think we might want to handle Windows file paths a different way.

Changing the Uri class to handle backslash file paths technically violates the URI spec. Instead the spec recommends converting the file paths to use forward slashes, which we could handle with a custom Mapper for Windows targets. Though I'm not sure how we would get the correct Windows path back afterwards to pass to Okio.

@Caij
Copy link
Author

Caij commented May 30, 2024

Sorry for the delay on merging this. After thinking about this I think we might want to handle Windows file paths a different way.

Changing the Uri class to handle backslash file paths technically violates the URI spec. Instead the spec recommends converting the file paths to use forward slashes, which we could handle with a custom Mapper for Windows targets. Though I'm not sure how we would get the correct Windows path back afterwards to pass to Okio.

Yes, I don't think my approach is very elegant, but I can't think of a better way to handle this, looking forward to your solutions.
Our current solution is set custom fetch factory for Windows targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants