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

Web Upload Treats UTF-16LE XML Files as Binary Despite .gitattributes #33733

Open
kool2zero opened this issue Feb 26, 2025 · 2 comments
Open
Labels

Comments

@kool2zero
Copy link

Description

Description

When uploading a UTF-16 Little Endian (without BOM) XML file to a Gitea repository via the web interface, the file is treated as binary, and textual diffs are not displayed. Committing the same file via the command line (or VS Code, which uses the command line) works correctly, with textual diffs shown as expected. This indicates that the issue is specific to the web upload process.

Issue Replicated in Demo

Steps to Reproduce

  1. Create a new Gitea repository.

  2. Create a .gitattributes file in the root of the repository with the following content:

    *.xml text working-tree-encoding=UTF-16LE eol=crlf
    
  3. Create an XML file (e.g., test.xml) encoded in UTF-16 Little Endian without a Byte Order Mark (BOM). You can use a text editor like Notepad++ or VS Code to ensure the correct encoding. A simple example file:

    <?xml version="1.0" encoding="UTF-16"?>
    <root>
        <element attribute="value1"/>
    </root>
  4. Commit and push the .gitattributes and test.xml files using the Git command line:

    git add .gitattributes test.xml
    git commit -m "Initial commit"
    git push origin main  # Or your branch name
  5. Modify the XML file locally. Change the attribute value (e.g., from "value1" to "value2"). Save the file (still as UTF-16LE, no BOM).

  6. Upload via the Web UI:

    • Go to your repository in Gitea's web interface.
    • Go to the Code tab and locate the xml.
    • Click the Edit button (pencil icon).
    • Paste the contents of the modified file.
    • Add a title to the commit and hit the Commit Changes button.
  7. View the diff: Go to the commit history and view the diff for the uploaded test.xml file.

Expected Behavior

The diff should be displayed as a textual diff, showing the change in the attribute value (e.g., "value1" to "value2").

Actual Behavior

The diff is displayed as a binary diff ("Binary files a/test.xml and b/test.xml differ").

Context

  • Gitea Version: 1.23.4
  • Operating System (Gitea Server): Windows Server 2019
  • Git Version (Server): git version 2.48.1.windows.1
  • Git Version (Client): git version 2.47.1.windows.1
  • Browser: Chrome 133
  • app.ini git section:
[git]
MAX_GIT_DIFF_LINES = 200000
MAX_GIT_DIFF_LINE_CHARACTERS = 5000
ENABLE_CHARSET_DETECTION = true

### Gitea Version

1.23.4

### Can you reproduce the bug on the Gitea demo site?

Yes

### Log Gist

https://gist.github.com/kool2zero/ab06322362cdafb7370db3ae3ebfca78

### Screenshots

After creating new branches and commiting via VS Code and the Web.

Initiating a pull request from the VSCode branch:

![Image](https://github.com/user-attachments/assets/c397c8ae-584f-47c8-84a7-1c5e23c63872)

Diff shows properly:

![Image](https://github.com/user-attachments/assets/3ce3cabd-024e-4292-9c36-0a9e26d77c8c)

Trying to initiate the pull request from the UploadFromWeb Branch:

![Image](https://github.com/user-attachments/assets/f2ff698c-cb96-46aa-a312-c6697f734c20)

Shows it as a binary file difference:

![Image](https://github.com/user-attachments/assets/a54b7114-eac2-4912-9deb-1695919ebf47)


### Git Version

git version 2.48.1.windows.1

### Operating System

Windows 2019

### How are you running Gitea?

I am using the Windows executable run via NSSM.

### Database

PostgreSQL
@delvh
Copy link
Member

delvh commented Feb 26, 2025

Image
?

@kool2zero
Copy link
Author

Check the diff between the two auxiliary branches during a pull request. When the file is pushed via vs code, the diff seems to work. When the file is uploaded via the web interface, it does not. The file is treated as binary...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants