Skip to content

Commit

Permalink
INT-1297: Preserve whitespace for byte array results
Browse files Browse the repository at this point in the history
  • Loading branch information
sarus committed Aug 9, 2024
1 parent 7fee711 commit 16965e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/getDisplayResults.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
const fp = require('lodash/fp');

const CHARCODE_SPACE = 32;
const CHARCODE_TAB = 9;
const CHARCODE_LINE_FEED = 10;
const CHARCODE_LINE_TABULATION = 11;
const CHARCODE_FORM_FEED = 12;
const CHARCODE_CARRIAGE_RETURN = 13;

const PRINTABLE_WHITESPACE_CHARACTERS = [
CHARCODE_SPACE,
CHARCODE_TAB,
CHARCODE_LINE_FEED,
CHARCODE_LINE_TABULATION,
CHARCODE_FORM_FEED,
CHARCODE_CARRIAGE_RETURN
];

const getByteArrayDisplayResults = (resultValue) => {
const stringifiedByteArray = String.fromCharCode.apply(
null,
resultValue.filter((x) => x > 32)
resultValue.filter((x) => x > 31 || PRINTABLE_WHITESPACE_CHARACTERS.includes(x))
);

return {
displayResult: stringifiedByteArray,
outputLength: fp.flow(fp.toString, fp.size)(stringifiedByteArray),
Expand Down
3 changes: 2 additions & 1 deletion styles/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ pre {

&.output {
line-height: 15px;
font-size: 11px;
font-size: 12px;

.output-title {
margin-bottom: 4px;
Expand Down Expand Up @@ -1135,6 +1135,7 @@ pre {
.show-whitespace {
white-space: pre-wrap;
word-wrap: break-word;
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.error-message {
Expand Down

0 comments on commit 16965e1

Please sign in to comment.