Commit bde04273 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '288006-binary2' into 'master'

Use `binary` property on the file object

See merge request gitlab-org/gitlab!68705
parents f9b8e1e5 56913167
......@@ -44,8 +44,8 @@ const KNOWN_TYPES = [
];
export function isTextFile({ name, raw, binary, content, mimeType = '' }) {
// some file objects already have a `binary` property set on them. If true, return false
if (binary) return false;
// some file objects already have a `binary` property set on them. If so, use it first
if (typeof binary === 'boolean') return !binary;
const knownType = KNOWN_TYPES.find((type) => type.isMatch(mimeType, name));
if (knownType) return knownType.isText;
......
......@@ -90,6 +90,9 @@ describe('WebIDE utils', () => {
it('returns true if there is a `binary` property already set on the file object', () => {
expect(isTextFile({ name: 'abc.txt', content: '' })).toBe(true);
expect(isTextFile({ name: 'abc.txt', content: '', binary: true })).toBe(false);
expect(isTextFile({ name: 'abc.tex', content: 'éêė' })).toBe(false);
expect(isTextFile({ name: 'abc.tex', content: 'éêė', binary: false })).toBe(true);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment