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(link): Don't throw exception on invalid URL href #6794

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

mejo-
Copy link
Member

@mejo- mejo- commented Dec 17, 2024

When pasting strings with invalid URLs, new URL() in renderHTML() of the Link extension threw an error, which made the paste parser choke.

We should catch this exception and handle it gracefully to not break HTML parsing completely with invalid URLs.

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests

@mejo- mejo- added bug Something isn't working 3. to review labels Dec 17, 2024
@mejo- mejo- added this to the Nextcloud 31 milestone Dec 17, 2024
@mejo- mejo- requested a review from juliusknorr December 17, 2024 12:44
@mejo- mejo- self-assigned this Dec 17, 2024
@mejo- mejo- requested a review from max-nextcloud as a code owner December 17, 2024 12:44
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 46.89%. Comparing base (1353d69) to head (d182756).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/marks/Link.js 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6794      +/-   ##
==========================================
+ Coverage   46.86%   46.89%   +0.02%     
==========================================
  Files         747      732      -15     
  Lines       34080    34065      -15     
  Branches     1240     1226      -14     
==========================================
+ Hits        15973    15976       +3     
+ Misses      17486    17483       -3     
+ Partials      621      606      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mejo-
Copy link
Member Author

mejo- commented Dec 17, 2024

/backport to stable30

@mejo-
Copy link
Member Author

mejo- commented Dec 17, 2024

/backport to stable29

? domHref(mark, this.options.relativePath)
: '#'
} catch (error) {
href = mark.attrs.href
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd also fall back to '#' here as we have no way of checking if this is a protocol we actually want to link to.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, changed now.

@max-nextcloud
Copy link
Collaborator

The Reuse check failure is really odd... looks like there are some licenses we sometimes use and sometimes don't.

When pasting strings with invalid URLs, `new URL()` in `renderHTML()` of
the Link extension threw an error, which made the paste parser choke.

We should catch this exception and handle it gracefully to not break
HTML parsing completely with invalid URLs.

Signed-off-by: Jonas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review bug Something isn't working
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

3 participants