Skip to content

Conversation

@vishalnarkhede
Copy link
Contributor

@vishalnarkhede vishalnarkhede commented Feb 25, 2021

Related ZD #9383

Fixes

  • Ignore email address from generating og preview
  • sanitize the urls before using Linking module from react-native

- Ignore email address from generating og preview
- sanitize the urls before using Linking module from react-native
Comment on lines 32 to 33
const urlRegex = /(?:[\w/:@-]+\.[\w/:@.-]*)+(?=\s|$)/g;
const emailRegex = /.*@.*/ ;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In discussion with Anatoly, for better regex!! Will replace it!

Copy link
Contributor

Choose a reason for hiding this comment

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

what if the url has an @ in the query params for some reason?

src/utils.js Outdated

// https://reactnative.dev/docs/linking
export const sanitizeUrlForLinking = (url) => {
if (url.indexOf('http://') === -1 && url.indexOf('https://') === -1) {
Copy link
Contributor

@virdesai virdesai Feb 25, 2021

Choose a reason for hiding this comment

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

pretty much the same thing

Suggested change
if (url.indexOf('http://') === -1 && url.indexOf('https://') === -1) {
if (!/^https?:\/\//.test(url)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently there is http.com lol, so wanted to avoid that!!

Copy link
Contributor

Choose a reason for hiding this comment

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

alright updated it with regex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks alot @virdesai :)

Comment on lines 32 to 33
const urlRegex = /(?:[\w/:@-]+\.[\w/:@.-]*)+(?=\s|$)/g;
const emailRegex = /.*@.*/ ;
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the url has an @ in the query params for some reason?


const urlRegex = /(https?:\/\/[^\s]+)/gi;

const urlRegex = /(?:\s|^)((?:https?:\/\/)?(?:[a-z0-9-]+(?:\.[a-z0-9-]+)+)(?::[0-9]+)?(?:\/(?:[^\s]+)?)?)/g;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks to @AnatolyRugalev !! Works pretty well - https://regex101.com/r/3ms9WF/1/

@vishalnarkhede vishalnarkhede merged commit b9a5217 into master Mar 5, 2021
@delete-merged-branch delete-merged-branch bot deleted the vishal/linking-fix branch March 5, 2021 16:17
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.

3 participants