-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Fix HTML tags appearing in wiki table of contents #36284
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
base: main
Are you sure you want to change the base?
Fix HTML tags appearing in wiki table of contents #36284
Conversation
|
Could you add some test? |
f0b0b36 to
d737929
Compare
|
Whether any |
|
Good question! I went with stripping all HTML tags rather than just The heading itself still renders with the HTML in the document body, so anchor links like I think adding an option would be overkill for this - can't think of a case where someone would actually want raw HTML showing up in their ToC. But happy to discuss if you see it differently! |
|
|
So, I think 'raw HTML' is useful when it is only accidentally HTML. |
d737929 to
a1c7525
Compare
|
Good edge case to think about! I tested this and the fix handles it correctly: ToC shows: Click and Bold The HTML tags get stripped but the text content inside them is preserved - which is exactly what we want for a readable ToC. I've added test cases covering this scenario. Also verified that code spans like |
e211fab to
0b84de7
Compare
0b84de7 to
e211fab
Compare
|
I fixed the tests, it needs to clearly assert what we want. And we can see that the result doesn't seem good. By the way: no need to rebase or force push, see the contribution guideline https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#maintaining-open-prs
|
|
Roger that, I'll step back. |

Fixes #36106
When wiki headings contain HTML elements (like
<a name="anchor"></a>), the raw HTML code was appearing verbatim in the table of contents instead of being stripped out.This fix uses bluemonday.StrictPolicy() to sanitize the heading text before adding it to the ToC, removing all HTML tags while preserving the text content.
Before: ToC displays
<a name="asdf"></a> has strange htmlAfter: ToC displays
has strange html