Skip to content

Commit

Permalink
fixed unittest for wrong escape sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
mariopaumann committed Jun 19, 2018
1 parent 0548ec4 commit 11cf054
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/InfluxDB/LineProtocol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '"';
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion t/10_basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use strict;
use warnings;
use 5.012;
use lib 'lib';
use Test::Most;
use InfluxDB::LineProtocol qw(data2line line2data);

Expand Down Expand Up @@ -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],
],
[
Expand Down
1 change: 1 addition & 0 deletions t/11_precision.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use strict;
use warnings;
use 5.012;
use lib 'lib';

BEGIN {
*CORE::GLOBAL::time = sub() {1437072205};
Expand Down
1 change: 1 addition & 0 deletions t/30_legacy_0_9_2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 11cf054

Please sign in to comment.