From f704170c6b2029f7c8b92b8a313ed0f0d5b7d6ed Mon Sep 17 00:00:00 2001 From: Carlos Revillo Date: Fri, 9 Dec 2022 15:07:23 +0100 Subject: [PATCH 1/3] fix passing null as 3rd argument to str_replace --- src/Prometheus/RenderTextFormat.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Prometheus/RenderTextFormat.php b/src/Prometheus/RenderTextFormat.php index a5b78dc..b6ded5e 100644 --- a/src/Prometheus/RenderTextFormat.php +++ b/src/Prometheus/RenderTextFormat.php @@ -56,9 +56,9 @@ private function renderSample(MetricFamilySamples $metric, Sample $sample): stri */ private function escapeLabelValue($v): string { - $v = str_replace("\\", "\\\\", $v); - $v = str_replace("\n", "\\n", $v); - $v = str_replace("\"", "\\\"", $v); + $v = str_replace("\\", "\\\\", $v ?? ''); + $v = str_replace("\n", "\\n", $v ?? ''); + $v = str_replace("\"", "\\\"", $v ?? ''); return $v; } } From 6ef1381ac89d3c4d0f4dd571cfc6754b3f3f12fa Mon Sep 17 00:00:00 2001 From: Carlos Revillo Date: Thu, 22 Dec 2022 07:21:55 +0100 Subject: [PATCH 2/3] allow php8 for this library --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f2f8b90..5f8aaf8 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "jimdo/prometheus_client_php": "*" }, "require": { - "php": "^7.2", + "php": "^7.2||^8.0", "ext-json": "*", "guzzlehttp/guzzle": "^6.3", "symfony/polyfill-apcu": "^1.6" From d0482f2458c2f02164329b1a1733c0023b18f2d7 Mon Sep 17 00:00:00 2001 From: Carlos Revillo Date: Thu, 22 Dec 2022 08:14:27 +0100 Subject: [PATCH 3/3] fix problem with str_replace --- src/Prometheus/RenderTextFormat.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Prometheus/RenderTextFormat.php b/src/Prometheus/RenderTextFormat.php index b6ded5e..a314a60 100644 --- a/src/Prometheus/RenderTextFormat.php +++ b/src/Prometheus/RenderTextFormat.php @@ -56,9 +56,9 @@ private function renderSample(MetricFamilySamples $metric, Sample $sample): stri */ private function escapeLabelValue($v): string { - $v = str_replace("\\", "\\\\", $v ?? ''); - $v = str_replace("\n", "\\n", $v ?? ''); - $v = str_replace("\"", "\\\"", $v ?? ''); + $v = str_replace("\\", "\\\\", $v ? (string)$v : ''); + $v = str_replace("\n", "\\n", $v ? (string)$v : ''); + $v = str_replace("\"", "\\\"", $v ? (string)$v : ''); return $v; } }