Skip to content

Commit 5ee4a4d

Browse files
Merge pull request #13496 from rhamilto/OCPBUGS-18699
OCPBUGS-18699: add additional check to determine if file is binary
2 parents 3546f35 + 94e255d commit 5ee4a4d

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

frontend/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@
135135
"@lezer/common": "^1.0.0",
136136
"@lezer/highlight": "^1.0.0",
137137
"@lezer/lr": "^1.0.0",
138+
"@patternfly-4/patternfly": "npm:@patternfly/patternfly@4.224.5",
139+
"@patternfly-4/quickstarts": "npm:@patternfly/quickstarts@2.4.2",
140+
"@patternfly-4/react-catalog-view-extension": "npm:@patternfly/react-catalog-view-extension@4.96.1",
141+
"@patternfly-4/react-console": "npm:@patternfly/react-console@4.13.4",
142+
"@patternfly-4/react-core": "npm:@patternfly/react-core@4.278.0",
143+
"@patternfly-4/react-icons": "npm:@patternfly/react-icons@4.93.7",
144+
"@patternfly-4/react-styles": "npm:@patternfly/react-styles@4.92.8",
145+
"@patternfly-4/react-table": "npm:@patternfly/react-table@4.113.6",
146+
"@patternfly-4/react-tokens": "npm:@patternfly/react-tokens@4.94.7",
138147
"@patternfly/patternfly": "5.1.0",
139148
"@patternfly/quickstarts": "5.1.0",
140149
"@patternfly/react-catalog-view-extension": "5.0.0",
@@ -148,15 +157,6 @@
148157
"@patternfly/react-topology": "5.1.0",
149158
"@patternfly/react-user-feedback": "5.0.0",
150159
"@patternfly/react-virtualized-extension": "5.1.0",
151-
"@patternfly-4/patternfly": "npm:@patternfly/patternfly@4.224.5",
152-
"@patternfly-4/quickstarts": "npm:@patternfly/quickstarts@2.4.2",
153-
"@patternfly-4/react-catalog-view-extension": "npm:@patternfly/react-catalog-view-extension@4.96.1",
154-
"@patternfly-4/react-console": "npm:@patternfly/react-console@4.13.4",
155-
"@patternfly-4/react-core": "npm:@patternfly/react-core@4.278.0",
156-
"@patternfly-4/react-icons": "npm:@patternfly/react-icons@4.93.7",
157-
"@patternfly-4/react-styles": "npm:@patternfly/react-styles@4.92.8",
158-
"@patternfly-4/react-table": "npm:@patternfly/react-table@4.113.6",
159-
"@patternfly-4/react-tokens": "npm:@patternfly/react-tokens@4.94.7",
160160
"@prometheus-io/codemirror-promql": "^0.37.0",
161161
"@rjsf/core": "^2.5.1",
162162
"abort-controller": "3.0.0",
@@ -183,6 +183,7 @@
183183
"i18next-http-backend": "^1.0.21",
184184
"i18next-v4-format-converter": "^1.0.3",
185185
"immutable": "3.x",
186+
"istextorbinary": "^9.5.0",
186187
"js-base64": "^2.5.1",
187188
"js-yaml": "^3.13.1",
188189
"json-schema": "^0.3.0",
@@ -299,8 +300,8 @@
299300
"glob": "7.x",
300301
"glslify-loader": "^2.0.0",
301302
"graphql-tag": "^2.10.3",
302-
"html-webpack-plugin": "3.x",
303303
"html-webpack-exclude-assets-plugin": "^0.0.7",
304+
"html-webpack-plugin": "3.x",
304305
"husky": "^8.0.3",
305306
"i18next-parser": "^8.9.0",
306307
"i18next-pseudo": "^2.2.0",

frontend/public/components/utils/file-input.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ConnectDropTarget, DropTargetMonitor } from 'react-dnd/lib/interfaces';
66
import { Alert } from '@patternfly/react-core';
77
/* eslint-disable-next-line */
88
import { withTranslation, WithTranslation } from 'react-i18next';
9+
import { isBinary } from 'istextorbinary/edition-es2017/index';
910

1011
import withDragDropContext from './drag-drop-context';
1112

@@ -46,7 +47,7 @@ class FileInputWithTranslation extends React.Component<FileInputProps, FileInput
4647
? (reader.result as string).split(',')[1]
4748
: (reader.result as string);
4849
// OnLoad, if inputFileIsBinary we have read as a binary string, skip next block
49-
if (containsNonPrintableCharacters(input) && !fileIsBinary) {
50+
if (containsNonPrintableCharacters(input) && isBinary(null, input) && !fileIsBinary) {
5051
fileIsBinary = true;
5152
reader.readAsDataURL(file);
5253
} else {
@@ -177,7 +178,9 @@ const DroppableFileInputWithTranslation = withDragDropContext(
177178
inputFileName: '',
178179
inputFileData: this.props.inputFileData || '',
179180
inputFileIsBinary:
180-
this.props.inputFileIsBinary || containsNonPrintableCharacters(this.props.inputFileData),
181+
this.props.inputFileIsBinary ||
182+
(containsNonPrintableCharacters(this.props.inputFileData) &&
183+
isBinary(null, this.props.inputFileData)),
181184
};
182185
this.handleFileDrop = this.handleFileDrop.bind(this);
183186
this.onDataChange = this.onDataChange.bind(this);
@@ -201,7 +204,7 @@ const DroppableFileInputWithTranslation = withDragDropContext(
201204
reader.onload = () => {
202205
const input = reader.result as string; // Note(Yaacov): we use reader.readAsText
203206
// OnLoad, if inputFileIsBinary we have read as a binary string, skip next block
204-
if (containsNonPrintableCharacters(input) && !inputFileIsBinary) {
207+
if (containsNonPrintableCharacters(input) && isBinary(null, input) && !inputFileIsBinary) {
205208
inputFileIsBinary = true;
206209
reader.readAsBinaryString(file);
207210
} else {

frontend/yarn.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,6 +4383,13 @@ binary-extensions@^2.0.0:
43834383
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
43844384
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==
43854385

4386+
binaryextensions@^6.11.0:
4387+
version "6.11.0"
4388+
resolved "https://registry.yarnpkg.com/binaryextensions/-/binaryextensions-6.11.0.tgz#c36b3e6b5c59e621605709b099cda8dda824cc72"
4389+
integrity sha512-sXnYK/Ij80TO3lcqZVV2YgfKN5QjUWIRk/XSm2J/4bd/lPko3lvk0O4ZppH6m+6hB2/GTu+ptNwVFe1xh+QLQw==
4390+
dependencies:
4391+
editions "^6.21.0"
4392+
43864393
bindings@^1.5.0:
43874394
version "1.5.0"
43884395
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
@@ -7194,6 +7201,13 @@ ecdsa-sig-formatter@1.0.11:
71947201
dependencies:
71957202
safe-buffer "^5.0.1"
71967203

7204+
editions@^6.21.0:
7205+
version "6.21.0"
7206+
resolved "https://registry.yarnpkg.com/editions/-/editions-6.21.0.tgz#8da2d85611106e0891a72619b7bee8e0c830089b"
7207+
integrity sha512-ofkXJtn7z0urokN62DI3SBo/5xAtF0rR7tn+S/bSYV79Ka8pTajIIl+fFQ1q88DQEImymmo97M4azY3WX/nUdg==
7208+
dependencies:
7209+
version-range "^4.13.0"
7210+
71977211
ee-first@1.1.1:
71987212
version "1.1.1"
71997213
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
@@ -10618,6 +10632,15 @@ istanbul-reports@^3.1.4:
1061810632
html-escaper "^2.0.0"
1061910633
istanbul-lib-report "^3.0.0"
1062010634

10635+
istextorbinary@^9.5.0:
10636+
version "9.5.0"
10637+
resolved "https://registry.yarnpkg.com/istextorbinary/-/istextorbinary-9.5.0.tgz#e6e13febf1c1685100ae264809a4f8f46e01dfd3"
10638+
integrity sha512-5mbUj3SiZXCuRf9fT3ibzbSSEWiy63gFfksmGfdOzujPjW3k+z8WvIBxcJHBoQNlaZaiyB25deviif2+osLmLw==
10639+
dependencies:
10640+
binaryextensions "^6.11.0"
10641+
editions "^6.21.0"
10642+
textextensions "^6.11.0"
10643+
1062110644
iterall@^1.2.1, iterall@^1.2.2:
1062210645
version "1.3.0"
1062310646
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea"
@@ -16048,6 +16071,13 @@ text-table@^0.2.0:
1604816071
version "0.2.0"
1604916072
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
1605016073

16074+
textextensions@^6.11.0:
16075+
version "6.11.0"
16076+
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-6.11.0.tgz#864535d09f49026150c96f0b0d79f1fa0869db15"
16077+
integrity sha512-tXJwSr9355kFJI3lbCkPpUH5cP8/M0GGy2xLO34aZCjMXBaK3SoPnZwr/oWmo1FdCnELcs4npdCIOFtq9W3ruQ==
16078+
dependencies:
16079+
editions "^6.21.0"
16080+
1605116081
thenify-all@^1.0.0:
1605216082
version "1.6.0"
1605316083
resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726"
@@ -16897,6 +16927,11 @@ verror@1.10.0, verror@^1.9.0:
1689716927
core-util-is "1.0.2"
1689816928
extsprintf "^1.2.0"
1689916929

16930+
version-range@^4.13.0:
16931+
version "4.14.0"
16932+
resolved "https://registry.yarnpkg.com/version-range/-/version-range-4.14.0.tgz#91c12e4665756a9101d1af43faeda399abe0edec"
16933+
integrity sha512-gjb0ARm9qlcBAonU4zPwkl9ecKkas+tC2CGwFfptTCWWIVTWY1YUbT2zZKsOAF1jR/tNxxyLwwG0cb42XlYcTg==
16934+
1690016935
victory-area@^36.6.11:
1690116936
version "36.6.11"
1690216937
resolved "https://registry.yarnpkg.com/victory-area/-/victory-area-36.6.11.tgz#8e67cdd9b4c77ac6373c39c794f7b4f86393f9ef"

0 commit comments

Comments
 (0)