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

Hyperlink markdown doesn't work if the ] is preceded by an ( #4229

Closed
5 tasks done
isagoico opened this issue Jul 26, 2021 · 18 comments · Fixed by Expensify/expensify-common#401 or #4295
Closed
5 tasks done

Hyperlink markdown doesn't work if the ] is preceded by an ( #4229

isagoico opened this issue Jul 26, 2021 · 18 comments · Fixed by Expensify/expensify-common#401 or #4295
Assignees
Labels
Engineering External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@isagoico
Copy link

isagoico commented Jul 26, 2021

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Navigate to a conversation
  2. Send this message
    [Yo (click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg)
  3. Check the message in the history

Expected Result:

The link should be hyperlinked even if there is a ) before the ].

Actual Result:

Link is not hyperlinked. Checked on Github and it gets hyperlinked correctly so this seems like an issue.
Important: Same happens for other punctuation marks.

Example
Yo (click here to see a cool cat)

Workaround:

User can send the link without the formatting

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.0.80-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos:

image

Expensify/Expensify Issue URL:

View all open jobs on Upwork


From @mallenexpensify https://expensify.slack.com/archives/C01GTK53T8Q/p1627271189249400

Markdown doesn't work when ] is preceded by )

@MelvinBot
Copy link

Triggered auto assignment to @AndrewGable (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

@AndrewGable AndrewGable added the External Added to denote the issue can be worked on by a contributor label Jul 26, 2021
@MelvinBot
Copy link

Triggered auto assignment to @NicMendonca (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@MelvinBot MelvinBot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 27, 2021
@NicMendonca
Copy link
Contributor

@NicMendonca NicMendonca removed the Daily KSv2 label Jul 27, 2021
@mananjadhav
Copy link
Collaborator

mananjadhav commented Jul 27, 2021

Proposal:

This can be fixed by updating the regex in ExpensiMark.js of expensify-common. Can handle other characters too by updating the regex.


{
                name: "link",
                process: (textToProcess, replacement) => {
                    const regex = new RegExp(
                        `\\[((?:[\\w\\s\\d!?&#;:\\(\\)\\/\\-\\.\\+=<>,@\\[\\]‘’“”]|(?:<code>.+<\\/code>))+)\\]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`,
                        "gi"
                    );
                    return this.modifyTextForUrlLinks(
                        regex,
                        textToProcess,
                        replacement
                    );
                },

                // We use a function here to check if there is already a https:// on the link.
                // If there is not, we force the link to be absolute by prepending '//' to the target.
                replacement: (match, g1, g2, g3) =>
                    `<a href="${
                        g3 && g3.includes("http") ? "" : "http://"
                    }${g2}" target="_blank">${g1}</a>`,
            },


@Santhosh-Sellavel
Copy link
Collaborator

Proposal

Changes should be done against expensify-common.

In the following lines.
https://github.com/Expensify/expensify-common/blob/7d8408c5c78792394eee8e079f115b1380221a23/lib/ExpensiMark.js#L72-L81

We missed handling for () also additionally we missed for$, %, *, | symbol,

Need replace regex prefix \\[((?:[\\w\\s\\d!?&#;:\\/\\-\\.\\+=<>,

with string to for () handling,
\[((?:[\w\s\d!?&#;:\/\-\.\+=<>(),

for other characters also.
\[((?:[\w\s\d!?&#;:\/\-\.\+=<>()$|%*,

@UHaider
Copy link

UHaider commented Jul 27, 2021

As mentioned in the issue it is happening for other punctuations as well, we can update the regex for link rule, this will handle {}*() along with existing supported punctuations

Here is the proposal

Proposal

                process: (textToProcess, replacement) => {
                    const regex = new RegExp(
                        `\\[((?:[\\w\\s\\d!?&#;:\\/\\-\\.\\+=<>,@\\[\\]\\(\\)\\'\\"\\*\\{\\}‘’“”]|(?:<code>.+<\\/code>))+)\\]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`,
                        'gi'
                    );
                    return this.modifyTextForUrlLinks(regex, textToProcess, replacement);
                },

                // We use a function here to check if there is already a https:// on the link.
                // If there is not, we force the link to be absolute by prepending '//' to the target.
                replacement: (match, g1, g2, g3) => (
                    `<a href="${g3 && g3.includes('http') ? '' : 'http://'}${g2}" target="_blank">${g1}</a>`
                ),
            },

DEMO
https://user-images.githubusercontent.com/17588033/127191146-e832a99d-99fa-41be-9755-f627550ab954.mov

@parasharrajat
Copy link
Member

I would suggest please run the test suite on e-common and mention that in your proposal if that is a pass.

@AndrewGable
Copy link
Contributor

I agree @parasharrajat. @mananjadhav since you were the first to comment, can you verify that the tests pass with your proposed regex? If so, we will hire you for the solution. Thank you!

@mananjadhav
Copy link
Collaborator

@AndrewGable @parasharrajat Sure. I'll add a test in a while and update here with the result.

@mananjadhav
Copy link
Collaborator

@AndrewGable @parasharrajat I've raised a PR with the test cases and the regex change.

Changed the approach to ensure none of the existing test cases break and also support multiple other special characters.

@AndrewGable
Copy link
Contributor

Looks great on first pass, I will review it further shortly. @NicMendonca - Can you please hire @mananjadhav via Upwork? Thanks!

@NicMendonca
Copy link
Contributor

@mananjadhav hired!

@AndrewGable
Copy link
Contributor

@mananjadhav Please open an App PR with the updated hash. Thanks!

@mananjadhav
Copy link
Collaborator

@AndrewGable Raised PR. Would you be needing screenshots for this PR? Tests in expensify-common cover the testing. Let me know.

@AndrewGable
Copy link
Contributor

Yes please, screenshots are required for all PRs 👍

@mananjadhav
Copy link
Collaborator

@AndrewGable Screencasts added for all platforms. Let me know if anything else is required to merge this.

@mananjadhav
Copy link
Collaborator

@NicMendonca Any updates on Upwork for this?

@NicMendonca
Copy link
Contributor

@mananjadhav yup! As per this information here, contracts are paid 7 days after the pull request is merged to allow for regression testing. Payment is scheduled to be issued in 2 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment