.conf files not being rendered for preview because it thinks its binary #12499

Closed
opened 2025-11-02 10:11:48 -06:00 by GiteaMirror · 15 comments
Owner

Originally created by @acidvegas on GitHub (Feb 18, 2024).

Description

On github this file can be viewed.
On gitea this same file can not be.

It is confusing it for a binary file because there is some Unicode inside the .conf which is needed.

Screenshots

2024-02-18-150139_670x198_scrot

Gitea Version

1.21

Can you reproduce the bug on the Gitea demo site?

Yes

Operating System

No response

Browser Version

Firefox Latest (THIS IS NOT A BROWSER ISSUE LOL)

Originally created by @acidvegas on GitHub (Feb 18, 2024). ### Description On github [this](https://github.com/acidvegas/weechat/blob/master/alias.conf) file can be viewed. On gitea [this same file](https://git.supernets.org/acidvegas/weechat/src/branch/master/alias.conf) can not be. It is confusing it for a binary file because there is some Unicode inside the .conf which is needed. ### Screenshots ![2024-02-18-150139_670x198_scrot](https://github.com/go-gitea/gitea/assets/14335118/8b698e3a-dfb4-41ec-a945-bca00d4cc5b9) ### Gitea Version 1.21 ### Can you reproduce the bug on the Gitea demo site? Yes ### Operating System _No response_ ### Browser Version Firefox Latest (THIS IS NOT A BROWSER ISSUE LOL)
GiteaMirror added the topic/content-renderingtopic/uitype/bug labels 2025-11-02 10:11:48 -06:00
Author
Owner

@delvh commented on GitHub (Feb 18, 2024):

Please file an issue upstream with go-enry.

@delvh commented on GitHub (Feb 18, 2024): Please file an issue upstream with [go-enry](https://github.com/go-enry/go-enry).
Author
Owner

@silverwind commented on GitHub (Apr 17, 2024):

I checked the file, it does not contain any 0-bytes, so maybe entry is not to blame. Enry basically looks for any 0-bytes in the first 8000 bytes:

53f5aa9866/utils.go (L101-L111)

@silverwind commented on GitHub (Apr 17, 2024): I checked the file, it does not contain any 0-bytes, so maybe entry is not to blame. Enry basically looks for any 0-bytes in the first 8000 bytes: https://github.com/go-enry/go-enry/blob/53f5aa9866cad881a5857fb5058f986c55bdba9f/utils.go#L101-L111
Author
Owner

@silverwind commented on GitHub (May 31, 2024):

Not a upstream bug as per discussion in https://github.com/go-enry/go-enry/issues/176.

@silverwind commented on GitHub (May 31, 2024): Not a upstream bug as per discussion in https://github.com/go-enry/go-enry/issues/176.
Author
Owner

@silverwind commented on GitHub (May 31, 2024):

Attaching the file in question here:

alias.txt

@silverwind commented on GitHub (May 31, 2024): Attaching the file in question here: [alias.txt](https://github.com/user-attachments/files/15513703/alias.txt)
Author
Owner

@lunny commented on GitHub (Jul 6, 2025):

Uploaded the file to https://gitea.com/lunny/test-render/src/branch/main/alias_file.txt

@lunny commented on GitHub (Jul 6, 2025): Uploaded the file to https://gitea.com/lunny/test-render/src/branch/main/alias_file.txt
Author
Owner

@wxiaoguang commented on GitHub (Jul 7, 2025):

It is a binary file (0x02, 0x03, 0x0f)

Image
@wxiaoguang commented on GitHub (Jul 7, 2025): It is a binary file (0x02, 0x03, 0x0f) <img width="970" height="434" alt="Image" src="https://github.com/user-attachments/assets/bf181303-c8f4-44f7-8f02-a9599d02a0df" />
Author
Owner

@lunny commented on GitHub (Jul 7, 2025):

But Github can display it. https://github.com/lunny/test-one-text/blob/main/alias.txt

@lunny commented on GitHub (Jul 7, 2025): But Github can display it. https://github.com/lunny/test-one-text/blob/main/alias.txt
Author
Owner

@wxiaoguang commented on GitHub (Jul 7, 2025):

But Github can display it. https://github.com/lunny/test-one-text/blob/main/alias.txt

Is GitHub always right? Where are these 0x02, 0x03 and 0x0f bytes when the file is displayed or edited? Is there any widely-used editor can handle these characters?

@wxiaoguang commented on GitHub (Jul 7, 2025): > But Github can display it. https://github.com/lunny/test-one-text/blob/main/alias.txt Is GitHub always right? Where are these `0x02`, `0x03` and `0x0f` bytes when the file is displayed or edited? Is there any widely-used editor can handle these characters?
Author
Owner

@lunny commented on GitHub (Jul 7, 2025):

I don't think Github will always be right. I just record how Github handle this file.

And another record, this is how VSCode display the file.

Image
@lunny commented on GitHub (Jul 7, 2025): I don't think Github will always be right. I just record how Github handle this file. And another record, this is how VSCode display the file. <img width="994" height="448" alt="Image" src="https://github.com/user-attachments/assets/be2c55af-8014-4a5b-a4a6-282e5d24b532" />
Author
Owner

@silverwind commented on GitHub (Jul 7, 2025):

We need to re-define our own IsBinary function most likely to handle such edge-cases.

@silverwind commented on GitHub (Jul 7, 2025): We need to re-define our own `IsBinary` function most likely to handle such edge-cases.
Author
Owner

@silverwind commented on GitHub (Jul 7, 2025):

0x02 and 0x03 should not trigger enry IsBinary from what I can tell, only 0x00 should?

@silverwind commented on GitHub (Jul 7, 2025): 0x02 and 0x03 should not trigger enry `IsBinary` from what I can tell, only 0x00 should?
Author
Owner

@wxiaoguang commented on GitHub (Jul 7, 2025):

0x02 and 0x03 should not trigger enry IsBinary from what I can tell, only 0x00 should?

Would you like to edit a such file via the online editor? How would these characters be rendered and edited?

Image
@wxiaoguang commented on GitHub (Jul 7, 2025): > 0x02 and 0x03 should not trigger enry `IsBinary` from what I can tell, only 0x00 should? Would you like to edit a such file via the online editor? How would these characters be rendered and edited? <img width="2432" height="1142" alt="Image" src="https://github.com/user-attachments/assets/d8e4ae61-79b6-4fb6-a468-8c2fb221f8f3" />
Author
Owner

@silverwind commented on GitHub (Jul 7, 2025):

Probably by rendering placeholders like this (from Firefox raw view):

Image

GitHub and Chrome does not render these chars at all which is bad. I guess we would at least need to verify first which characters GitHub does not consider binary. Likely its using some Ruby library for this.

@silverwind commented on GitHub (Jul 7, 2025): Probably by rendering placeholders like this (from Firefox [raw view](https://raw.githubusercontent.com/lunny/test-one-text/refs/heads/main/alias.txt)): <img width="78" height="42" alt="Image" src="https://github.com/user-attachments/assets/c5f6edf7-55ec-40d3-990b-31b127d81a30" /> GitHub and Chrome does not render these chars at all which is bad. I guess we would at least need to verify first which characters GitHub does not consider binary. Likely its using some Ruby library for this.
Author
Owner

@wxiaoguang commented on GitHub (Jul 7, 2025):

But it is a very rare case. I seldom see "text" files really containing these "print control chars".

Why such files should be considered as "text"? How would users edit them and input these chars?

@wxiaoguang commented on GitHub (Jul 7, 2025): But it is a very rare case. I seldom see "text" files really containing these "print control chars". Why such files should be considered as "text"? How would users edit them and input these chars?
Author
Owner

@silverwind commented on GitHub (Jul 7, 2025):

IDK, most of the time, I think text files containing control characters are errors, but I think it might occur sometimes that you have literal control characters in source code. In any case, rendering parity with GitHub/GitLab would be nice but it requires research in what exactly they consider binary.

@silverwind commented on GitHub (Jul 7, 2025): IDK, most of the time, I think text files containing control characters are errors, but I think it might occur sometimes that you have literal control characters in source code. In any case, rendering parity with GitHub/GitLab would be nice but it requires research in what exactly they consider binary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12499