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

Fix client crash due to long output #998

Merged
merged 2 commits into from
Mar 22, 2024
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
21 changes: 21 additions & 0 deletions library/Icingadb/Util/PluginOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class PluginOutput extends HtmlString
/** @var bool Whether the output contains HTML */
protected $isHtml;

/** @var int The maximum amount of characters to process */
protected $characterLimit = 1000;

/** @var bool Whether output will be enriched */
protected $enrichOutput = true;

Expand Down Expand Up @@ -93,6 +96,20 @@ public function isHtml(): bool
return $this->isHtml;
}

/**
* Set the maximum amount of characters to process
*
* @param int $limit
*
* @return $this
*/
public function setCharacterLimit(int $limit): self
{
$this->characterLimit = $limit;

return $this;
}

/**
* Set whether the output should be enriched
*
Expand Down Expand Up @@ -185,6 +202,10 @@ public function render()
$output = $this->processHtml($output);
}

if ($this->characterLimit) {
$output = substr($output, 0, $this->characterLimit);
}

$this->renderedOutput = $output;

return $output;
Expand Down
5 changes: 4 additions & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ protected function createPluginOutput(): array
if (empty($this->object->state->output) && empty($this->object->state->long_output)) {
$pluginOutput = new EmptyState(t('Output unavailable.'));
} else {
$pluginOutput = new PluginOutputContainer(PluginOutput::fromObject($this->object));
$pluginOutput = new PluginOutputContainer(
PluginOutput::fromObject($this->object)
->setCharacterLimit(10000)
);
CopyToClipboard::attachTo($pluginOutput);
}

Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline-7x.neon
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ parameters:
count: 1
path: library/Icingadb/Util/PerfData.php

-
message: "#^Method Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:render\\(\\) should return string but returns string\\|false\\|null\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Parameter \\#1 \\$str of function trim expects string, string\\|null given\\.$#"
count: 1
Expand All @@ -135,6 +140,11 @@ parameters:
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Property Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:\\$renderedOutput \\(string\\) does not accept string\\|false\\|null\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Parameter \\#1 \\$str of function trim expects string, mixed given\\.$#"
count: 1
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline-8x.neon
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,21 @@ parameters:
count: 1
path: library/Icingadb/Util/PerfData.php

-
message: "#^Method Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:render\\(\\) should return string but returns string\\|null\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|null given\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Property Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:\\$renderedOutput \\(string\\) does not accept string\\|null\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Parameter \\#1 \\$string of function trim expects string, mixed given\\.$#"
count: 1
Expand Down
12 changes: 1 addition & 11 deletions phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5040,11 +5040,6 @@ parameters:
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Method Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:render\\(\\) should return string but returns string\\|null\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Parameter \\#1 \\$html of method Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:processHtml\\(\\) expects string, string\\|null given\\.$#"
count: 1
Expand All @@ -5067,19 +5062,14 @@ parameters:

-
message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|null given\\.$#"
count: 2
count: 3
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Parameter \\#2 \\$subject of function preg_match expects string, string\\|null given\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Property Icinga\\\\Module\\\\Icingadb\\\\Util\\\\PluginOutput\\:\\:\\$renderedOutput \\(string\\) does not accept string\\|null\\.$#"
count: 1
path: library/Icingadb/Util/PluginOutput.php

-
message: "#^Method Icinga\\\\Module\\\\Icingadb\\\\Web\\\\Control\\\\GridViewModeSwitcher\\:\\:getTitle\\(\\) should return string but returns string\\|null\\.$#"
count: 1
Expand Down
Loading