Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Data/Printer/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ sub _escape_chars {

my $escape_kind = $ddp->escape_chars;
my %target_for = (
nonascii => '[^\x{00}-\x{7f}]+',
nonlatin1 => '[^\x{00}-\x{ff}]+',
nonascii => '[^\x{00}-\x{7f}]+',
nonlatin1 => '[^\x{00}-\x{ff}]+',
nonprintable => '\P{Print}',
);

if ($ddp->unicode_charnames) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Printer/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ sub _init {
$props,
'escape_chars',
'none',
[qw(none nonascii nonlatin1 all)]
[qw(none nonascii nonlatin1 nonprintable all)]
);
$self->{'caller_info'} = Data::Printer::Common::_fetch_scalar_or_default($props, 'caller_info', 0);
$self->{'caller_message'} = Data::Printer::Common::_fetch_scalar_or_default(
Expand Down
11 changes: 10 additions & 1 deletion t/002-scalar.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ^^ taint mode must be on for taint checking.
use strict;
use warnings;
use Test::More tests => 72;
use Test::More tests => 73;
use Data::Printer::Object;
use Scalar::Util;

Expand Down Expand Up @@ -114,6 +114,15 @@ sub test_escape_chars {
'escaping nonascii'
);

# All the $string content is printable, so we'll add a non-printable
# character to see it escaped.
$object = Data::Printer::Object->new( colored => 0, escape_chars => 'nonprintable' );
is(
$object->parse(\"\cX $string"), # ^X is U+0018, CANCEL
qq("\\x{18} $string"),
'escaping nonprintable'
);

$object = Data::Printer::Object->new( colored => 0, escape_chars => 'nonascii', unicode_charnames => 1 );
is(
$object->parse(\$string),
Expand Down