Skip to content

Commit

Permalink
Merge branch 'rel-10_1' into issue-#1081-perl_5_34_0_buster
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Jun 12, 2021
2 parents 1d85b7f + 9a20b5f commit 8fa33a0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
58 changes: 40 additions & 18 deletions Kernel/System/Encode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -262,37 +262,49 @@ sub Convert2CharsetInternal {

=head2 EncodeInput()
Convert internal used charset (e. g. utf-8) into given charset (utf-8).
Assume that the incoming data is binary data containing UTF-8 encoded strings. Turn the data
into Perl strings with the proper semantics.
Should be used on all I/O interfaces if data is already utf-8 to set the utf-8 stamp.
Should be used on all I/O interfaces if data is already utf-8 to set the UTF8 flag.
Note that the method name is a misnomer. The method should be DecodeInput().
$EncodeObject->EncodeInput( \$String );
# @Array may contain only undef and strings
$EncodeObject->EncodeInput( \@Array );
=cut

sub EncodeInput {
my ( $Self, $What ) = @_;

return if !defined $What;
return unless defined $What;

if ( ref $What eq 'SCALAR' ) {
return $What if !defined ${$What};
Encode::_utf8_on( ${$What} );
return $What unless defined $What->$*;

# assuming the the incoming string is already encoded in UTF-8
Encode::_utf8_on( $What->$* );

return $What;
}

if ( ref $What eq 'ARRAY' ) {

ROW:
for my $Row ( @{$What} ) {
next ROW if !defined $Row;
Encode::_utf8_on($Row);
STRING:
for my $String ( $What->@* ) {
next STRING unless defined $String;

# assuming the the incoming string is already encoded in UTF-8
Encode::_utf8_on($String);
}

return $What;
}

# assuming the the incoming string is already encoded in UTF-8
# TODO: It is not documented that strings can be passed in directly.
Encode::_utf8_on($What);

return $What;
Expand All @@ -307,6 +319,8 @@ This should be used in for output of utf-8 chars.
$EncodeObject->EncodeOutput( \$String );
# @Array may contain only undef and references to strings
# Note that this is a different type of array as supported in EncodeInput().
$EncodeObject->EncodeOutput( \@Array );
=cut
Expand All @@ -315,25 +329,33 @@ sub EncodeOutput {
my ( $Self, $What ) = @_;

if ( ref $What eq 'SCALAR' ) {
return $What if !defined ${$What};
return $What if !Encode::is_utf8( ${$What} );
${$What} = Encode::encode_utf8( ${$What} );
return $What unless defined $What->$*;
return $What unless Encode::is_utf8( $What->$* );

$What->$* = Encode::encode_utf8( $What->$* );

return $What;
}

if ( ref $What eq 'ARRAY' ) {

ROW:
for my $Row ( @{$What} ) {
next ROW if !defined $Row;
next ROW if !Encode::is_utf8( ${$Row} );
${$Row} = Encode::encode_utf8( ${$Row} );
STRING_REF:
for my $StringRef ( @{$What} ) {
next STRING_REF unless defined $StringRef;
next STRING_REF unless Encode::is_utf8( $StringRef->$* );

$StringRef->$* = Encode::encode_utf8( $StringRef->$* );
}

return $What;
}

return $What if !Encode::is_utf8( \$What );
# TODO: it is not documented that anything but scalar or array refs can be passed as argument
# TODO: it is not obvious what is_utf8() or encode_utf8() do with references
return $What unless Encode::is_utf8( \$What );

Encode::encode_utf8( \$What );

return $What;
}

Expand Down
15 changes: 9 additions & 6 deletions Kernel/System/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,18 @@ sub Log {
$Self->{ lc $Priority }->{Message} = $Message;
}

# write shm cache log
# Prepend the current log line to the shared memory segment.
# The oldest log lines might fall out of the window.
# shmwrite() might append "\0" bytes for padding.
if ( lc $Priority ne 'debug' && $Self->{IPC} ) {

$Priority = lc $Priority;

my $Data = $LogTime . ";;$Priority;;$Self->{LogPrefix};;$Message\n";
my $String = $Self->GetLog();

shmwrite( $Self->{IPCSHMKey}, $Data . $String, 0, $Self->{IPCSize} ) || die $!;
my $LogLine = join ';;', $LogTime, $Priority, $Self->{LogPrefix}, $Message;
my $OldString = $Self->GetLog();
my $NewString = join "\n", $LogLine, $OldString;
$Kernel::OM->Get('Kernel::System::Encode')->EncodeOutput( \$NewString );
shmwrite( $Self->{IPCSHMKey}, $NewString, 0, $Self->{IPCSize} ) || die $!;
}

return 1;
Expand Down Expand Up @@ -315,7 +318,7 @@ sub GetLog {
# Remove \0 bytes that shmwrite adds for padding.
$String =~ s{\0}{}smxg;

# encode the string
# the string is UTF-8 encoded, decode it (even though the method is called EncodeInput)
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput( \$String );

return $String;
Expand Down

0 comments on commit 8fa33a0

Please sign in to comment.