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

Markdown Links: Fix redirection href values #666

Merged
merged 19 commits into from
Jun 1, 2021
Merged

Markdown Links: Fix redirection href values #666

merged 19 commits into from
Jun 1, 2021

Conversation

seanlowjk
Copy link
Contributor

@seanlowjk seanlowjk commented Mar 22, 2021

Summary

This PR fixes #663

Description

When a user generated an invalid link using one of the two methods below, a error gets thrown and the app entirely crashes despite of the platform being used. (Desktop or Web Version). The possible errors generated are from either one of these two 'invalid' links

  1. [Link](invalidlink), an invalid link
  2. [Link](www.google.com), a valid link without the http or https header

Fix Done

As a result, we would need to override the rendered in MarkedRenderer from ngx-markdown such that we able to achieve the functionality as below:

Simply open the new link in a new tab and propagate the error there. As a result, current progress would not be lost.

Suggested Commit Message:

Markdown Links: Fix redirection href values

Our application crashes when an invalid link is rendered as HTML 
and the user clicks on the HTML Link. This is because there are no
checks done before the link is rendered. 

Let's open these links in a new tabs and propagate these errors there 
such that current users do not lose their current progress with respect 
to bug reports and other form data. 

@seanlowjk seanlowjk requested a review from a team March 22, 2021 07:22
@seanlowjk seanlowjk marked this pull request as ready for review March 22, 2021 07:22
Copy link
Contributor

@dingyuchen dingyuchen left a comment

Choose a reason for hiding this comment

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

LGTM code wise 👍

I would like to point out a possible side effect that we missed out, which is that our newly defined rendering behavior does not change the underlying body of the issue.
This means that while students are able to use the link on CATcher, they will not be able to do so if they choose the view the issue on GitHub.

So while this PR saves CATcher from hard crashes, it also introduces behavior that is inconsistent with the GitHub comment editor. This can be solved by applying the changes directly to the issue body. Perhaps it is worth discussing the desirability of these changes @CATcher-org/2021-devs

return linkRenderer.call(renderer, href, title, text);
} else {
const html = linkRenderer.call(renderer, href, title, text);
console.log(html);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be removed or logged with our logger instead of the console log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I forgot to remove the debug statement my bad 😓

@seanlowjk
Copy link
Contributor Author

As discussed, I have made the changes and updated the PR! Do let me know if there is anything I have missed out! >< @dingyuchen @kkangs0226

@codecov-io
Copy link

codecov-io commented Mar 28, 2021

Codecov Report

Merging #666 (d141f14) into master (6a3c5e8) will decrease coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #666      +/-   ##
==========================================
- Coverage   69.08%   68.99%   -0.09%     
==========================================
  Files          76       76              
  Lines        2274     2274              
  Branches      208      208              
==========================================
- Hits         1571     1569       -2     
  Misses        660      660              
- Partials       43       45       +2     
Impacted Files Coverage Δ
src/app/shared/issue-tables/issue-sorter.ts 44.00% <0.00%> (-8.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a3c5e8...d141f14. Read the comment docs.

@anubh-v anubh-v added this to the V3.3.8 milestone Mar 28, 2021
Copy link
Contributor

@dingyuchen dingyuchen left a comment

Choose a reason for hiding this comment

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

LGTM!

@seanlowjk seanlowjk requested a review from anubh-v April 17, 2021 09:28
Copy link
Contributor

@ptvrajsk ptvrajsk left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@codecov-commenter
Copy link

codecov-commenter commented Apr 21, 2021

Codecov Report

Merging #666 (f154408) into master (8294718) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #666      +/-   ##
==========================================
+ Coverage   69.90%   69.92%   +0.01%     
==========================================
  Files          79       80       +1     
  Lines        2369     2377       +8     
  Branches      215      215              
==========================================
+ Hits         1656     1662       +6     
  Misses        668      668              
- Partials       45       47       +2     
Impacted Files Coverage Δ
src/app/shared/lib/marked.ts 100.00% <100.00%> (ø)
src/app/shared/issue-tables/issue-sorter.ts 44.00% <0.00%> (-8.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8294718...f154408. Read the comment docs.

Copy link
Contributor

@anubh-v anubh-v left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @seanlowjk - I just have a suggestion that we could add a test for this fix

src/app/shared/lib/marked.ts Show resolved Hide resolved
@seanlowjk
Copy link
Contributor Author

@anubh-v @ptvrajsk @dingyuchen have added a simple test, do let me know if there are changes to be made!

@anubh-v anubh-v merged commit a685122 into CATcher-org:master Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: No way to recover from clicking on invalid markdown link
6 participants