@@ -52,8 +52,8 @@ protected function tagsToString(array $tags)
5252 {
5353 $ tagLine = "" ;
5454 if (count ($ tags ) > 0 ) {
55- array_walk ($ tags , function (&$ value , $ key ) {
56- $ value = "{$ key }= {$ value }" ;
55+ array_walk ($ tags , function (&$ value , $ key ) {
56+ $ value = "{$ this -> addSlashes ( $ key) }= {$ this -> addSlashes ( $ value) }" ;
5757 });
5858 $ tagLine = sprintf (",%s " , implode (", " , $ tags ));
5959 }
@@ -63,15 +63,15 @@ protected function tagsToString(array $tags)
6363
6464 protected function pointsToString (array $ elements )
6565 {
66- array_walk ($ elements , function (&$ value , $ key ) {
66+ array_walk ($ elements , function (&$ value , $ key ) {
6767 $ dataType = gettype ($ value );
6868 if (!in_array ($ dataType , ["string " , "double " , "boolean " , "integer " ])) {
6969 $ dataType = "serializable " ;
7070 }
7171 $ dataType = ucfirst ($ dataType );
7272 if ($ dataType !='Null ' ) {
7373 $ value = call_user_func ([$ this , "convert {$ dataType }" ], $ value );
74- $ value = "{$ key }= {$ value }" ;
74+ $ value = "{$ this -> addSlashes ( $ key) }= {$ value }" ;
7575 }
7676 });
7777 $ elements = array_filter ($ elements );
@@ -102,4 +102,23 @@ protected function convertBoolean($value)
102102 {
103103 return (($ value ) ? "true " : "false " );
104104 }
105+
106+ /**
107+ * Returns strings with space, comma, or equals sign characters backslashed per Influx write protocol syntax
108+ *
109+ * @param string $value
110+ * @return string
111+ */
112+ private function addSlashes ($ value )
113+ {
114+ return str_replace ([
115+ ' ' ,
116+ ', ' ,
117+ '= '
118+ ], [
119+ '\ ' ,
120+ '\, ' ,
121+ '\= '
122+ ], $ value );
123+ }
105124}
0 commit comments