Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip ANSI codes from logs #6801

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/frontend/common/pipes/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import {CommaSeparatedPipe} from './commaseparated';
import {CoreFormatter} from './coreformatter';
import {MemoryFormatter} from './memoryformatter';
import {RelativeTimeFormatter} from './relativetime';
import {SafeHtmlFormatter} from './safehtml';
import {StripAnsiPipe} from './stripansi';
import {TrimPipe} from './trim';

@NgModule({
declarations: [
MemoryFormatter,
CoreFormatter,
RelativeTimeFormatter,
SafeHtmlFormatter,
StripAnsiPipe,
TrimPipe,
CommaSeparatedPipe,
FilterByPipe,
Expand All @@ -38,7 +38,7 @@ import {TrimPipe} from './trim';
MemoryFormatter,
CoreFormatter,
RelativeTimeFormatter,
SafeHtmlFormatter,
StripAnsiPipe,
TrimPipe,
CommaSeparatedPipe,
FilterByPipe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@ import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
import stripAnsi from 'strip-ansi';

/**
* Formats the given value as raw HTML to display to the user.
* Strips ANSI codes from string.
*/
@Pipe({name: 'kdSafeHtml'})
export class SafeHtmlFormatter {
constructor(private readonly sanitizer: DomSanitizer) {}

@Pipe({name: 'kdStripAnsi'})
export class StripAnsiPipe {
transform(value: string): SafeHtml {
value = stripAnsi(value);
value = this.escape_(value);
return this.sanitizer.sanitize(SecurityContext.HTML, value);
}

private escape_(unsafe: string): string {
return unsafe
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
return stripAnsi(value);
}
}
2 changes: 1 addition & 1 deletion src/app/frontend/logs/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
fxLayoutGap="2px">
<div *ngFor="let item of logsSet"
[ngClass]="{'kd-logs-element-compact': logService.getCompact(), 'kd-logs-element': !logService.getCompact()}">
<span>{{item}}</span>
<span>{{item | kdStripAnsi}}</span>
</div>
</div>
</div>
Expand Down