Protect stdout and stderr so JavaScript code can't accidentally write to stdout corrupting ink rendering (#13247)

Bypassing rules as link checker failure is spurious.
This commit is contained in:
Jacob Richman
2025-11-20 10:44:02 -08:00
committed by GitHub
parent e20d282088
commit d1e35f8660
82 changed files with 1523 additions and 868 deletions
+6 -13
View File
@@ -27,11 +27,11 @@ export class ConsolePatcher {
}
patch() {
console.log = this.patchConsoleMethod('log', this.originalConsoleLog);
console.warn = this.patchConsoleMethod('warn', this.originalConsoleWarn);
console.error = this.patchConsoleMethod('error', this.originalConsoleError);
console.debug = this.patchConsoleMethod('debug', this.originalConsoleDebug);
console.info = this.patchConsoleMethod('info', this.originalConsoleInfo);
console.log = this.patchConsoleMethod('log');
console.warn = this.patchConsoleMethod('warn');
console.error = this.patchConsoleMethod('error');
console.debug = this.patchConsoleMethod('debug');
console.info = this.patchConsoleMethod('info');
}
cleanup = () => {
@@ -45,20 +45,13 @@ export class ConsolePatcher {
private formatArgs = (args: unknown[]): string => util.format(...args);
private patchConsoleMethod =
(
type: 'log' | 'warn' | 'error' | 'debug' | 'info',
originalMethod: (...args: unknown[]) => void,
) =>
(type: 'log' | 'warn' | 'error' | 'debug' | 'info') =>
(...args: unknown[]) => {
if (this.params.stderr) {
if (type !== 'debug' || this.params.debugMode) {
this.originalConsoleError(this.formatArgs(args));
}
} else {
if (this.params.debugMode) {
originalMethod.apply(console, args);
}
if (type !== 'debug' || this.params.debugMode) {
this.params.onNewMessage?.({
type,