Keep the encoding declared in downloaded files

Open
#1,795 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start in DownloadFileRequestHandler around lines 89-90, then compare the response reset used by ExternalRequestHandler and the /file/* encoding settings in web.xml. Check MIMETypeUtils.MIMETypeForFileExtension and MIMETypes.properties when handling extensions case-insensitively. Done means XML responses omit the forced charset while other formats retain current behavior, and the documented windows-1251 XML download renders correctly.

Written by the indexing model from the issue text.

Description

Description

A file that declares its own encoding other than UTF-8 is shown wrong in the web client: an XML file fails with error on line 2 at column 1: Encoding error instead of the document, and an HTML file with <meta charset="windows-1251"> is shown garbled. The web client sends every file as UTF-8, and the browser trusts this over the encoding declared in the file itself.

Steps to reproduce:

  1. Run an action that opens a file:
    openFile() {
        INPUT f = FILE DO
            open(f);
    }
    
  2. Pick an XML file in windows-1251, for example an EDI document that starts with <?xml version="1.0" encoding="windows-1251"?> and has Cyrillic text, or an HTML report in windows-1251 with <meta charset="windows-1251">.
  3. The browser shows Encoding error for the XML file and garbled text for the HTML file.

Affects 6.3 and 7.0.

Reason

XML exchange formats (EDI, 1C exports and others) and older HTML reports often use windows-1251, and such files cannot be viewed from the web client.

Fix

A file that declares its encoding (an XML declaration with encoding, an HTML <meta> with charset, a CSS @charset) is sent without an encoding, so the browser reads the one declared in the file. Files that declare nothing (txt, csv, XML and HTML without a declaration, …) are still sent as UTF-8: without it, browsers guess their encoding from the user's locale and show UTF-8 text garbled.

Dominant language
Java
Stars
214
Forks
46
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lsfusion/platform

All issues in lsfusion/platform

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.