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

Don't render escaped HTML on plain text #21841

Closed
wants to merge 2 commits into from

Conversation

Gusted
Copy link
Contributor

@Gusted Gusted commented Nov 16, 2022

  • While viewing a plain readme file that has ambiguous characters, it currently will write HTML for escaped characters, however it's being rendered as a plain text and thus will not actually render the HTML elements.
  • Only show the escape status, but render the content as plain text without trying to show the ambigious characters(escape button will have no effect due to this).
  • Related https://codeberg.org/Codeberg/Community/issues/796

Before:
image

After:
image

- While viewing a plain readme file that has ambiguous characters, it
currently will write HTML for escaped characters, however it's being
rendered as a plain text and thus will not actually render the HTML
elements.
- Only show the escape status, but render the content as plain text
without trying to show the ambigious characters(escape button will have
no effect due to this).
- Related https://codeberg.org/Codeberg/Community/issues/796
@Gusted
Copy link
Contributor Author

Gusted commented Nov 16, 2022

@zeripath, this feels hacky, but trying to render the plain text as HTML feels even more hacky.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 16, 2022
@zeripath
Copy link
Contributor

Yup this PR doesn't feel right to me.

@Gusted
Copy link
Contributor Author

Gusted commented Nov 17, 2022

What should be the expected behavior be, indeed render the HTML? Or disable this feature altogether for plain READMEs?

@zeripath
Copy link
Contributor

zeripath commented Nov 22, 2022

So there are two things we need to do:

  1. In reality we should drop the ambiguous warnings for rendered content
    • We should be like VSCode here and github and only warn about these on Source code views
  2. We still need to do something about rendering README.txt files though, because we have to handle broken characters.
    • I think these should just be rendered as <pre> and we can stick the <code> bits in as necessary.

@silverwind
Copy link
Member

silverwind commented Nov 27, 2022

Related: I would suggest making this box yellow instead of red. Also, I think we should reduce text to just one paragraph, those two are nearly identical. And finally, I still feel the warning shows up too often on innocuous code.

@wxiaoguang
Copy link
Contributor

Related: I would suggest making this box yellow instead of red. Also, I think we should reduce text to just one paragraph, those two are nearly identical. And finally, I still feel the warning shows up too often on innocuous code.

Agree, many warnings do not make sense:

@Gusted
Copy link
Contributor Author

Gusted commented Dec 1, 2022

So there are two things we need to do:

1. In reality we should drop the ambiguous warnings for rendered content
   
   * We should be like VSCode here and github and only warn about these on Source code views

2. We still need to do something about rendering README.txt files though, because we have to handle broken characters.
   
   * I think these should just be rendered as  and we can stick the ```
      bits in as necessary.
     ````
   ``
   `

` `

So still stick in the html elements? But don't display them? I'm sorry I'm not following on your second point.

Copy link
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

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

Better than before

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 1, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 3, 2022
Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

I think this is still the wrong thing to do - instead we should just render the warning for rendered pages.

@zeripath
Copy link
Contributor

zeripath commented Dec 3, 2022

See #22017

zeripath added a commit to zeripath/gitea that referenced this pull request Dec 3, 2022
…mbiguous characters

As recognised in go-gitea#21841 the rendering of plain text files is somewhat
incorrect when there are ambiguous characters as the html code is double
escaped. In fact there are several more problems here.

We have a residual isRenderedHTML which is actually simply escaping the
file - not rendering it. This is badly named and gives the wrong
impression.

There is also unusual behaviour whether the file is called a Readme or
not and there is no way to get to the source code if the file is called
README.

In reality what should happen is different depending on whether the
file is being rendered a README at the bottom of the directory view or
not.

1. If it is rendered as a README on a directory - it should simply be
   escaped and rendered as `<pre>` text.
2. If it is rendered as a file then it should be rendered as source
   code.

This PR therefore does:
1. Rename IsRenderedHTML to IsRenderedPlainText
2. Readme files rendered at the bottom of the directory are rendered without line numbers
3. Otherwise plain text files are rendered as source code.

Replace go-gitea#21841

Signed-off-by: Andrew Thornton <art27@cantab.net>
@Gusted
Copy link
Contributor Author

Gusted commented Dec 4, 2022

Seems to be replaced by #22017

@Gusted Gusted closed this Dec 4, 2022
@zeripath
Copy link
Contributor

zeripath commented Dec 4, 2022

Thanks @Gusted for your work

lafriks pushed a commit that referenced this pull request Dec 17, 2022
…mbiguous characters (#22017)

As recognised in #21841 the rendering of plain text files is somewhat
incorrect when there are ambiguous characters as the html code is double
escaped. In fact there are several more problems here.

We have a residual isRenderedHTML which is actually simply escaping the
file - not rendering it. This is badly named and gives the wrong
impression.

There is also unusual behaviour whether the file is called a Readme or
not and there is no way to get to the source code if the file is called
README.

In reality what should happen is different depending on whether the file
is being rendered a README at the bottom of the directory view or not.

1. If it is rendered as a README on a directory - it should simply be
escaped and rendered as `<pre>` text.
2. If it is rendered as a file then it should be rendered as source
code.

This PR therefore does:
1. Rename IsRenderedHTML to IsPlainText
2. Readme files rendered at the bottom of the directory are rendered
without line numbers
3. Otherwise plain text files are rendered as source code.

Replace #21841

Signed-off-by: Andrew Thornton <art27@cantab.net>

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
zeripath added a commit to zeripath/gitea that referenced this pull request Dec 18, 2022
…mbiguous characters (go-gitea#22017)

Backport go-gitea#22017

As recognised in go-gitea#21841 the rendering of plain text files is somewhat
incorrect when there are ambiguous characters as the html code is double
escaped. In fact there are several more problems here.

We have a residual isRenderedHTML which is actually simply escaping the
file - not rendering it. This is badly named and gives the wrong
impression.

There is also unusual behaviour whether the file is called a Readme or
not and there is no way to get to the source code if the file is called
README.

In reality what should happen is different depending on whether the file
is being rendered a README at the bottom of the directory view or not.

1. If it is rendered as a README on a directory - it should simply be
escaped and rendered as `<pre>` text.
2. If it is rendered as a file then it should be rendered as source
code.

This PR therefore does:
1. Rename IsRenderedHTML to IsPlainText
2. Readme files rendered at the bottom of the directory are rendered
without line numbers
3. Otherwise plain text files are rendered as source code.

Replace go-gitea#21841

Signed-off-by: Andrew Thornton <art27@cantab.net>

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
lunny added a commit that referenced this pull request Dec 19, 2022
…mbiguous characters (#22017) (#22160)

Backport #22017

As recognised in #21841 the rendering of plain text files is somewhat
incorrect when there are ambiguous characters as the html code is double
escaped. In fact there are several more problems here.

We have a residual isRenderedHTML which is actually simply escaping the
file - not rendering it. This is badly named and gives the wrong
impression.

There is also unusual behaviour whether the file is called a Readme or
not and there is no way to get to the source code if the file is called
README.

In reality what should happen is different depending on whether the file
is being rendered a README at the bottom of the directory view or not.

1. If it is rendered as a README on a directory - it should simply be
escaped and rendered as `<pre>` text.
2. If it is rendered as a file then it should be rendered as source
code.

This PR therefore does:
1. Rename IsRenderedHTML to IsPlainText
2. Readme files rendered at the bottom of the directory are rendered
without line numbers
3. Otherwise plain text files are rendered as source code.

Replace #21841

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@Gusted Gusted deleted the dont-render-escape-plain branch December 20, 2022 21:51
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants