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: Modify replace_all to avoid infinite loop #1128

Closed
wants to merge 3 commits into from

Conversation

xiota
Copy link
Contributor

@xiota xiota commented Oct 29, 2021

This PR modifies replace_all to avoid the infinite loop. In each iteration, replace_all searches for needle starting from the beginning of haystack. If replacement contains needle, the result is an infinite loop. To prevent this from happening, replace_all should continue searching for needle from the end of the previous replacement.

Resolves #936.

markdown/src/viewer.c Outdated Show resolved Hide resolved
@xiota xiota requested a review from elextr October 29, 2021 10:45
@elextr
Copy link
Member

elextr commented Oct 29, 2021

There is a g_string_replace() that does replace all, but its very new, probably should keep this for now.

@elextr
Copy link
Member

elextr commented Oct 29, 2021

Looks ok to me, but I don't build or use markdown plugin, so I won't test it.

@xiota
Copy link
Contributor Author

xiota commented Oct 29, 2021

There is a g_string_replace() that does replace all, but its very new, probably should keep this for now.

Requires glib 2.68... Not available for Ubuntu LTS 18.04 (glib 2.54) or 20.04 (glib 2.64).

@elextr
Copy link
Member

elextr commented Oct 29, 2021

Yeah, thats why I called it "very new".

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.

When the "Markdown" plug-in is enabled, opening a markdown file containing "@@markdown@@" always freezes.
3 participants