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

Crash on Android if source is an invalid URL #407

Closed
raynor85 opened this issue Feb 17, 2019 · 15 comments · Fixed by #782
Closed

Crash on Android if source is an invalid URL #407

raynor85 opened this issue Feb 17, 2019 · 15 comments · Fixed by #782
Labels

Comments

@raynor85
Copy link

raynor85 commented Feb 17, 2019

If I pass as source an object like this { uri: 'INVALID_URL' } I get the following error on Android:

Error while updating property 'source' of a view managed by: FastImageView

null

Must not be null or empty

At the moment I am normalising the source using this (ugly) code to avoid the crash:

const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('https://')[1] ? null : source;

but I think it would be better if the library prevents it.

@OrangeFlavoredColdCoffee

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

@rj9676564
Copy link

rj9676564 commented Mar 28, 2019

image

this is log.

2019-03-28 19:29:08.185 14848-14848/E/fastimage: http://img.abc.com/o_1d6v24em310p7pib14b94gsjbha.jpg
2019-03-28 19:29:08.185 14848-14848/ E/fastimage: false
2019-03-28 19:29:08.195 14848-14848/ E/fastimage: true
2019-03-28 19:29:08.196 14848-14848/E/unknown:ViewManager: Error while updating prop source
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)


 Caused by: java.lang.ClassCastException: Value for uri cannot be cast from ReadableNativeMap to String

@Thrajnor
Copy link

Thrajnor commented May 5, 2019

@OrangeFlavoredColdCoffee Your answer works perfectly. Thank you very much! you saved me so much time ^^

@tianliuj
Copy link

tianliuj commented Sep 3, 2019

so I need adjust every source ? It's so Unfriendly!!!

@creative-dev-lab
Copy link

const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

You saved my day!

@osrl
Copy link

osrl commented Dec 11, 2019

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

not all images start with https or http. what about local images

@alexdieudonne
Copy link

how i could use this function or variable ?

@alexdieudonne
Copy link

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

not all images start with https or http. what about local images

i don't know where

@raynor85
Copy link
Author

raynor85 commented Apr 11, 2020 via email

@mrminhhuy
Copy link

render() {
return (
<FastImage source={{uri: this.getUriImage(_uri)}}/>
)
}

function getUriImage(uri) {
return uri !== null && uri !== undefined && uri.includes("/") && uri.includes(".") ? uri : ""
}

@leogildo10
Copy link

not all image start https, http ??

where do i have do make this change?

@cdw1p
Copy link

cdw1p commented Jul 6, 2020

render() {
return (
<FastImage source={{uri: this.getUriImage(_uri)}}/>
)
}

function getUriImage(uri) {
return uri !== null && uri !== undefined && uri.includes("/") && uri.includes(".") ? uri : ""
}

Thanks you, my problem is solved using this

@thanhdevapp
Copy link

Handler local image

class ProgressiveImage extends React.Component {

getUriImage(uri) {
    return uri !== null && uri !== undefined && uri.includes("/") && uri.includes(".") ? uri : ""
}

render() {
    let source = this.props.source;
    return (
        <View style={styles.container}>
            {this.props.source && this.props.source.uri ? <FastImage {...this.props} source={{
                uri: this.getUriImage(this.props.source.uri),
                cache: FastImage.cacheControl.immutable,
            }} /> : <Image {...this.props} />}
        </View>
    )
}

}

@z3r0c00l-2k
Copy link

I think the library itself should take of this issue, on ios it works perfectly.

@github-actions
Copy link

🎉 This issue has been resolved in version 8.5.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.