From 267ab03663159bbcc025138c64cae8ad39dfde05 Mon Sep 17 00:00:00 2001 From: dmitry krokhin Date: Tue, 16 Nov 2021 16:58:47 +0300 Subject: [PATCH] empty line parser fix --- src/Metrics/Importer/PrometheusImporter.php | 4 ++++ tests/Metrics/ImporterTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Metrics/Importer/PrometheusImporter.php b/src/Metrics/Importer/PrometheusImporter.php index e3d7982..0062bd4 100644 --- a/src/Metrics/Importer/PrometheusImporter.php +++ b/src/Metrics/Importer/PrometheusImporter.php @@ -49,6 +49,10 @@ private function parseInfoLine(string $line, string $prefix) private function parseDataLine(string $line, string $prefix) { + if (strpos($line, ' ') === false) { + return; + } + [$nick, $value] = explode(' ', $line); if ($prefix && strpos($nick, $prefix) === 0) { diff --git a/tests/Metrics/ImporterTest.php b/tests/Metrics/ImporterTest.php index 06c402a..c62f09f 100644 --- a/tests/Metrics/ImporterTest.php +++ b/tests/Metrics/ImporterTest.php @@ -15,6 +15,15 @@ class ImporterTest extends TestCase { + public function testInvalidLine(): void + { + $registry = new Registry(); + $info = new Info(); + $importer = new PrometheusImporter($registry, $info); + $importer->fromString(""); + $this->assertCount(0, $registry->toArray()); + } + public function testPrometheus(): void { $registry = new Registry();