gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.04k stars 7.54k forks source link

Rendering Issue caused by `<!--more-->` #12426

Open Junyi-99 opened 7 months ago

Junyi-99 commented 7 months ago

Hugo will produce a string of e>

Just try this in any of a theme:

---
title: "Demo - Summary Rendering Test 7 (😱 Bad Dream)"
date: 2024-04-25T1:54:18+08:00
draft: false
---

```c {linenos=table}
int main() {
    // Is your theme able to handle this?
    // Are the content below rendered correctly?
    return 0; // Only see this in the summary view
}
```

<!--<!--more-->

<mark>You MUST NOT see me in the preview</mark>

## Test Heading

The content below should also be hidden in the summary view.

<!--more-->

```html
Will <!--<!--more--> cause a rendering issue?
```

What version of Hugo are you using (hugo version)?

$ hugo v0.124.1-db083b05f16c945fec04f745f0ca8640560cf1ec+extended darwin/arm64 BuildDate=2024-03-20T11:40:10Z VendorInfo=brew

Does this issue reproduce with the latest release?

YES

Junyi-99 commented 7 months ago
image
Junyi-99 commented 6 months ago

As a rendering engine, Hugo simply uses string.find("<!--more-->") instead of using lexical parsing for <! --, which is a irresponsible behavior, as it makes it not easy for the user to debug.

I suggest that Hugo warns the user that there's a syntax error somewhere instead of just displaying the rendering crashed page. (if possible.)

This PR (#12437) provides a mitigation (since we should put <!--more--> at the beginning of a line)

bep commented 5 days ago

I'm closing this. I'm not going to complicate the parser to fix this. If this problem is real (which I doubt), it can be easily avoided by the user.