Changeset 18410


Ignore:
Timestamp:
2009-01-21T19:13:52+13:00 (15 years ago)
Author:
ak19
Message:

Some changes made in url and base64 encoding to deal with when the character entity for underscore had replaced the underscore (after dmsafing a filename so it won't cause conflicts with GS macros).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/unicode.pm

    r18404 r18410  
    584584    if (!&is_url_encoded($text)) {
    585585    $text =~ s/([^A-Z0-9\ \.\-\_])/sprintf("%%%02X", ord($1))/iseg;
     586    # return the url-encoded character entity for underscore back to the entity
     587    $text =~ s/%26%23095%3B/&\#095;/g;
    586588    }
    587589    return $text;
     
    608610    my ($text) =@_;
    609611    $text =~ s/%25/%/g if &is_url_encoded($text);
     612    # DM safing would have replaced underscores with character entity _
     613    # in SourceFile meta. Undo any such change to get the filename referred to.
     614    $text =~ s/&\#095;/_/g;
    610615    return $text;
    611616}
    612617
    613618# When a filename on the filesystem is already URL-encoded, the
    614 # URL to it will have %25s in in place of every % sign, so that
     619# URL to it will have %25s in place of every % sign, so that
    615620# URLs in html pages can refer to the URL-encoded filename.
    616621# Given a (URL-encoded) filename on the filesystem, this subroutine
     
    631636    my ($text) = @_;
    632637    if(!&conforms_to_mod_base64($text)) {
     638    # return entity for underscore to underscore before encoding
     639    $text =~ s/&\#095;/_/g;
     640
    633641    $text = &MIME::Base64::encode_base64($text);
    634642    # base64 encoding may introduce + and / signs,
     
    663671sub conforms_to_mod_base64 {
    664672    my ($text) = @_;
     673
     674    # need to treat the entity ref for underscore as underscore
     675    $text =~ s/&\#095;/_/g;
     676
    665677    # base 64 takes alphanumeric and [=+/],
    666678    # but we use modified base64 where + and / are replaced with  - and _
Note: See TracChangeset for help on using the changeset viewer.