From 86d350a3854af1a5a292972d4f70154e61ce5e80 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 11 Jan 2023 01:12:47 +0000 Subject: add mwrap-decode-csv tool This is a useful companion to the dump_csv: directive. It also fixes a bug where HTML escaping was unnecessarily done to the CSV output by -rproxy. --- lib/Devel/Mwrap/Rproxy.pm | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'lib/Devel/Mwrap/Rproxy.pm') diff --git a/lib/Devel/Mwrap/Rproxy.pm b/lib/Devel/Mwrap/Rproxy.pm index d5a9d9d..de65685 100644 --- a/lib/Devel/Mwrap/Rproxy.pm +++ b/lib/Devel/Mwrap/Rproxy.pm @@ -11,9 +11,8 @@ package Devel::Mwrap::Rproxy; use v5.12; # strict use Fcntl qw(SEEK_SET); use IO::Socket::UNIX; -use Plack::Util; -sub new { bless { socket_dir => $_[1]}, $_[0] } +sub new { require Plack::Util; bless { socket_dir => $_[1]}, $_[0] } sub r { [ $_[0], [ @@ -104,13 +103,26 @@ sub a2l { $a2l ? do { chomp(my $line = $a2l->lookup($addr)); $line =~ s/\Q?? at ??:0\E//; # FreeBSD - $line = Plack::Util::encode_html($line); $line =~ /\?\?/ ? "$line $exe($addr)" : ($line =~ /\S/ ? $line : "$exe($addr)"); } : "$exe($addr)" } } +sub decode_csv { + my ($in, $out) = @_; + while (<$in>) { + s/\\n/\0\0/g; + s!(["\0]) + ([^\("\0]+) # exe + \(([^\)"\0]+)\) # addr + (["\0])! + $1.a2l($2,$3).$4!gex; + s/\0\0/\\n/g; + $out->write($_); + } +} + sub call { # PSGI entry point my ($self, $env) = @_; my $uri = $env->{REQUEST_URI}; @@ -152,23 +164,16 @@ sub call { # PSGI entry point local %addr2line; # extract executable|library(address) if ($csv) { - while (<$c>) { - s/\\n/\0\0/g; - s!(["\0]) - ([^\("\0]+) # exe - \(([^\)"\0]+)\) # addr - (["\0])! - $1.a2l($2,$3).$4!gex; - s/\0\0/\\n/g; - $http_out->write($_); - } + decode_csv($c, $http_out); } else { while (<$c>) { s!> ([^\(<]+) # exe \(([^\)<]+)\) # addr '.a2l($1,$2).'<'!gex; + '>'.Plack::Util::encode_html( + a2l($1,$2)). + '<'!gex; $http_out->write($_); } } -- cgit v1.2.3-24-ge0c7