Skip to content

Commit

Permalink
Do not crash chip dialog if the prettify function fails (kubernetes#5108
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Marcin Maciaszczyk committed May 7, 2020
1 parent 1f66b1c commit 32dfa33
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/app/frontend/common/components/textinput/component.ts
Expand Up @@ -143,15 +143,19 @@ export class TextInputComponent implements OnInit, AfterViewInit, OnChanges {
return;
}

switch (this.mode) {
case 'json':
this.text = JSON.stringify(JSON.parse(this.text), null, '\t');
// Replace \n with new lines
this.text = this.text.replace(new RegExp(/\\n/g), '\n\t\t');
break;
default:
// Do nothing when mode is not recognized.
break;
try {
switch (this.mode) {
case 'json':
this.text = JSON.stringify(JSON.parse(this.text), null, '\t');
// Replace \n with new lines
this.text = this.text.replace(new RegExp(/\\n/g), '\n\t\t');
break;
default:
// Do nothing when mode is not recognized.
break;
}
} catch (e) {
// Ignore any errors in case of wrong format. Formatting will not be applied.
}
}
}

0 comments on commit 32dfa33

Please sign in to comment.