Ticket #3552: 800915-mc-url-unescape.patch

File 800915-mc-url-unescape.patch, 2.7 KB (added by onlyjob, 4 years ago)

proposed patch

  • lib/strescape.h

    diff -rNu mc-4.8.13/lib/strescape.h mc-new/lib/strescape.h
    old new  
    2929 
    3030gboolean strutils_is_char_escaped (const char *, const char *); 
    3131 
     32/* 
     33   In-place unescaping of http %xx sequences. 
     34*/ 
     35void strutils_url_unescape(char *buff); 
     36 
    3237#endif 
  • lib/strutil/strescape.c

    diff -rNu mc-4.8.13/lib/strutil/strescape.c mc-new/lib/strutil/strescape.c
    old new  
    253253} 
    254254 
    255255/* --------------------------------------------------------------------------------------------- */ 
     256 
     257/* unescape auxiliary function */ 
     258 
     259/* 
     260   returns the (integer) digit value to the character, 
     261   or -1 if not in the valid set '0' ... '9', 'A' ... F' 
     262*/ 
     263static unsigned int  
     264digit_heximal(char dig) 
     265{ 
     266 
     267  if ((dig >= '0') && (dig <= '9')) { 
     268    return dig - '0'; 
     269  } 
     270  if (dig > 'F') { dig -= 0x20; } 
     271  if ((dig >= 'A') && (dig <= 'F')) { 
     272    return dig - 0x37; 
     273  } 
     274  return -1; 
     275} 
     276 
     277/* 
     278  Scans the srce string converting valid %cc hex escapes to their 
     279  ascii representation into the dest string. 
     280  Srce and dest refer to the same buffer without any ill effects. 
     281*/ 
     282 
     283void 
     284strutils_url_unescape(char *buff) 
     285{ 
     286  char *psrc = buff; 
     287  char *pdst = buff; 
     288  short int hex8; 
     289  short int low8; 
     290  int copy = 0; 
     291 
     292  while (*psrc != 0) { 
     293    if (*psrc != '%') { 
     294      if (copy) { *pdst++ = *psrc++; continue; } 
     295      else { pdst++; psrc++; continue; } 
     296    } 
     297    copy = 1; 
     298    // %% escape ? 
     299    if (*(++psrc) == '%') { 
     300      *pdst++ = *psrc++; continue; 
     301    } 
     302    hex8 = 16 * digit_heximal(*psrc++); 
     303    low8 = digit_heximal(*psrc++); 
     304    if ((low8 | hex8) < 0) { 
     305      // not a valid url escape - leave unmodified 
     306      *pdst++ = '%'; 
     307      *pdst++ = *(psrc - 2); 
     308      *pdst++ = *(psrc - 1); 
     309    } else { 
     310      *pdst++ = (char) (hex8 + low8); 
     311    } 
     312  } 
     313  *pdst = 0; 
     314} 
     315 
     316/* --------------------------------------------------------------------------------------------- */ 
  • src/vfs/ftpfs/ftpfs.c

    diff -rNu mc-4.8.13/src/vfs/ftpfs/ftpfs.c mc-new/src/vfs/ftpfs/ftpfs.c
    old new  
    110110#include "lib/vfs/netutil.h" 
    111111#include "lib/vfs/xdirentry.h" 
    112112#include "lib/vfs/gc.h"         /* vfs_stamp_create */ 
     113#include "lib/strescape.h" 
    113114 
    114115#include "ftpfs.h" 
    115116 
     
    622623    else 
    623624        name = g_strdup (super->path_element->user); 
    624625 
     626    strutils_url_unescape(name); 
     627 
    625628    if (ftpfs_get_reply (me, SUP->sock, reply_string, sizeof (reply_string) - 1) == COMPLETE) 
    626629    { 
    627630        char *reply_up;