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

Detect empty links on markdown rendering and issue an error #884

Merged
merged 3 commits into from
Jan 11, 2020
Merged

Detect empty links on markdown rendering and issue an error #884

merged 3 commits into from
Jan 11, 2020

Conversation

zbrox
Copy link
Contributor

@zbrox zbrox commented Dec 19, 2019

Referencing #871

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

@@ -242,6 +242,10 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render

Event::Start(Tag::Image(link_type, src, title))
}
Event::Start(Tag::Link(link_type, link, title)) if link.is_empty() => {
error = Some(Error::msg("There is a link that is missing a URL"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add the link type/title to the error message?

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 actually had it with the title in the message initially but for some reason the title variable there is an empty string. I didn't have more time to look into it. My initial guess was that maybe the Markdown parser is not properly parsing a link without a URL.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah interesting, I'll see if I can reproduce it and open an issue on pulldown-cmark

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Keats did you manage to reproduce it? Is it really an issue or did I misunderstand something?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't tried yet, I'll check when I have time

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah nevermind, title is [I'm an inline-style link with title](https://www.google.com "Google's Homepage") Google's Homepage. It looks like you don't get the link text in the event

@Keats Keats marked this pull request as ready for review January 7, 2020 21:41
@Keats
Copy link
Collaborator

Keats commented Jan 8, 2020

A bit late but can you add a test for that?

@zbrox
Copy link
Contributor Author

zbrox commented Jan 8, 2020

A bit late but can you add a test for that?

Yeah, sure. I'll look into that.

let res = render_content(content, &context);

assert!(res.is_err());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Keats I was not terribly creative with the test. Should I test for something else other than erring out?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can check that the description contains the expected string

When testing for empty links detection compare the error message
to make sure it's the correct error that stopped the process
and not some unrelated issue.
@Keats Keats merged commit 42b7a5b into getzola:next Jan 11, 2020
@Keats
Copy link
Collaborator

Keats commented Jan 11, 2020

Thanks!

Keats pushed a commit that referenced this pull request Feb 3, 2020
* Detect empty links on markdown rendering and issue an error

* Add a test for empty links stopping rendering with an error

* Assert error message is the expected one

When testing for empty links detection compare the error message
to make sure it's the correct error that stopped the process
and not some unrelated issue.
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.

2 participants