From 0548ec4a22669ddc3b944a34a8a56bd9d6407b88 Mon Sep 17 00:00:00 2001 From: "APA-IT, Mario Paumann" Date: Fri, 15 Jun 2018 13:41:48 +0200 Subject: [PATCH 1/2] added unittest for wrong escape sequence --- t/10_basic.t | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/10_basic.t b/t/10_basic.t index 8571903..30536a4 100644 --- a/t/10_basic.t +++ b/t/10_basic.t @@ -191,6 +191,11 @@ my @tests = ( 'metric value="some \"value\""', ['metric', { value=>'some "value"' } , undef], ], + [ 0, + [ 'metric', 'some \"value\"' ], + 'metric value="some \\\\\"value\\\\\""', + [ 'metric', { value => 'some \"value\"' }, undef ], + ], # tag types # escape tags From 11cf05447d8fcdbd183850245f7c6257c3cc7e28 Mon Sep 17 00:00:00 2001 From: "APA-IT, Mario Paumann" Date: Tue, 19 Jun 2018 11:22:33 +0200 Subject: [PATCH 2/2] fixed unittest for wrong escape sequence --- lib/InfluxDB/LineProtocol.pm | 10 ++++++++-- t/10_basic.t | 3 ++- t/11_precision.t | 1 + t/30_legacy_0_9_2.t | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/InfluxDB/LineProtocol.pm b/lib/InfluxDB/LineProtocol.pm index f8e38da..02a8b35 100644 --- a/lib/InfluxDB/LineProtocol.pm +++ b/lib/InfluxDB/LineProtocol.pm @@ -77,7 +77,7 @@ sub _format_value { } else { # string actually, but this should be quoted differently? - $v =~ s/"/\\"/g; + $v =~ s/(["\\])/\\$1/g; $v = '"' . $v . '"'; } @@ -172,6 +172,7 @@ sub line2data { $line =~ s/\\ /ESCAPEDSPACE/g; $line =~ s/\\,/ESCAPEDCOMMA/g; $line =~ s/\\"/ESCAPEDDBLQUOTE/g; + $line =~ s/\\\\/ESCAPEDBACKSLASH/g; $line=~/^(.*?) (.*) (.*)$/; my ($key, $fields, $timestamp) = ( $1, $2, $3); @@ -200,7 +201,9 @@ sub line2data { my ( $k, $v ) = split( /=/, $valset ); $v =~ s/ESCAPEDSTRING_(\d+)/$strings[$1]/ge; $v =~ s/ESCAPEDDBLQUOTE/"/g; + $v =~ s/ESCAPEDBACKSLASH/\\/g; $v =~ s/^(-?\d+)i$/$1/; + $k =~ s/ESCAPEDBACKSLASH/\\\\/g; $values->{$k} = $v; } @@ -269,7 +272,7 @@ sub _data2line_0_9_2 { $v !~ /^(?:F(?:ALSE)?|f(?:alse)?|T(?:RUE)?|t(?:rue)?)$/ ) { - $v =~ s/"/\\"/g; + $v =~ s/(["\\])/\\$1/g; $v = '"' . $v . '"'; } push( @fields, $esc_k . '=' . $v ); @@ -286,6 +289,7 @@ sub _line2data_0_9_2 { $line =~ s/\\ /ESCAPEDSPACE/g; $line =~ s/\\,/ESCAPEDCOMMA/g; $line =~ s/\\"/ESCAPEDDBLQUOTE/g; + $line =~ s/\\\\/ESCAPEDBACKSLASH/g; $line=~/^(.*?) (.*) (.*)$/; my ($key, $fields, $timestamp) = ( $1, $2, $3); @@ -314,6 +318,8 @@ sub _line2data_0_9_2 { my ( $k, $v ) = split( /=/, $valset ); $v =~ s/ESCAPEDSTRING_(\d+)/$strings[$1]/ge; $v =~ s/ESCAPEDDBLQUOTE/"/g; + $v =~ s/ESCAPEDBACKSLASH/\\/g; + $k =~ s/ESCAPEDBACKSLASH/\\\\/g; $values->{$k} = $v; } diff --git a/t/10_basic.t b/t/10_basic.t index 30536a4..c36ebbd 100644 --- a/t/10_basic.t +++ b/t/10_basic.t @@ -2,6 +2,7 @@ use strict; use warnings; use 5.012; +use lib 'lib'; use Test::Most; use InfluxDB::LineProtocol qw(data2line line2data); @@ -228,7 +229,7 @@ my @tests = ( [ 0, ['disk_free',{ value=> 442221834240, 'working directories'=>'C:\My Documents\Stuff for examples,C:\My Documents'}], - 'disk_free value=442221834240i,working\ directories="C:\My Documents\Stuff for examples,C:\My Documents"', + 'disk_free value=442221834240i,working\ directories="C:\\\\My Documents\\\\Stuff for examples,C:\\\\My Documents"', ['disk_free',{ value=> 442221834240, 'working directories'=>'C:\My Documents\Stuff for examples,C:\My Documents'}, undef], ], [ diff --git a/t/11_precision.t b/t/11_precision.t index 9025d28..7fb6f1b 100644 --- a/t/11_precision.t +++ b/t/11_precision.t @@ -2,6 +2,7 @@ use strict; use warnings; use 5.012; +use lib 'lib'; BEGIN { *CORE::GLOBAL::time = sub() {1437072205}; diff --git a/t/30_legacy_0_9_2.t b/t/30_legacy_0_9_2.t index cd4d994..656753d 100644 --- a/t/30_legacy_0_9_2.t +++ b/t/30_legacy_0_9_2.t @@ -2,6 +2,7 @@ use strict; use warnings; use 5.012; +use lib 'lib'; use Test::Most; use InfluxDB::LineProtocol qw(v0.9.2 data2line line2data);