Changeset 34393

Show
Ignore:
Timestamp:
15.09.2020 20:19:33 (2 weeks ago)
Author:
ak19
Message:

Commit of independent code update before committing a bugfix. In this commit, the results of base64 encoding can have linebreaks, which aren't what we want or expect, so have a flag for removing them.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/unicode.pm

    r33757 r34393  
    708708    my ($text) = @_; 
    709709    my $force_encode = 1; 
    710     return &base64_encode($text, $force_encode); 
     710    my $no_newlines = 1; 
     711    return &base64_encode($text, $force_encode, $no_newlines); 
    711712} 
    712713 
    713714sub base64_encode { 
    714     my ($text, $force_encode) = @_; 
     715    my ($text, $force_encode, $no_newlines) = @_; 
    715716    if($force_encode || !&conforms_to_mod_base64($text)) { 
    716717    # return entity for underscore to underscore before encoding 
     
    722723    $text =~ s/\+/\-/g; # + -> - 
    723724    $text =~ s/\//\_/g; # / -> _ 
     725     
     726    # by default base64 encoding a long string introduces newlines to break long strings, 
     727    # see https://stackoverflow.com/questions/19952621/is-it-ok-to-remove-newline-in-base64-encoding 
     728    # Java doesn't like that 
     729    $text =~ s/\n//gs if $no_newlines; 
    724730    } 
    725731    return $text; 
     
    793799} 
    794800 
    795  
    796801sub raw_filename_to_url_encoded 
    797802{