Ticket #147: escaping-patch-rev2.patch

File escaping-patch-rev2.patch, 4.8 KB (added by Patrick Winnertz, 15 years ago)

Added by email2trac

  • src/command.c

    diff --git a/src/command.c b/src/command.c
    index b204b8d..7764e45 100644
    a b examine_cd (char *path) 
    6464    const char *t; 
    6565 
    6666    /* Tilde expansion */ 
     67    path = unescape_string(path); 
    6768    path_tilde = tilde_expand (path); 
    6869 
    6970    /* Leave space for further expansion */ 
  • src/complete.c

    diff --git a/src/complete.c b/src/complete.c
    index 1742b85..a11b9c9 100644
    a b  
    4040#include "wtools.h" 
    4141#include "complete.h" 
    4242#include "main.h" 
     43#include "util.h" 
    4344#include "key.h"                /* XCTRL and ALT macros */ 
    4445 
    4546typedef char *CompletionFunction (char *, int); 
    query_callback (Dlg_head *h, dlg_msg_t msg, int parm) 
    911912static int 
    912913complete_engine (WInput *in, int what_to_do) 
    913914{ 
     915    char *complete = NULL; 
    914916    if (in->completions && in->point != end) 
    915917        free_completions (in); 
    916918    if (!in->completions){ 
    complete_engine (WInput *in, int what_to_do) 
    924926    } 
    925927    if (in->completions){ 
    926928        if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { 
    927             if (insert_text (in, in->completions [0], strlen (in->completions [0]))){ 
     929            complete = escape_string(in->completions [0]); 
     930            if (insert_text (in, complete, strlen (complete))){ 
    928931                if (in->completions [1]) 
    929932                    beep (); 
    930933                else 
    complete_engine (WInput *in, int what_to_do) 
    940943            Dlg_head *query_dlg; 
    941944            WListbox *query_list; 
    942945             
    943             for (p=in->completions + 1; *p; count++, p++) 
     946            for (p=in->completions + 1; *p; count++, p++) { 
     947            *p = escape_string(*p); 
    944948                if ((i = strlen (*p)) > maxlen) 
    945949                    maxlen = i; 
     950                        } 
    946951            start_x = in->widget.x; 
    947952            start_y = in->widget.y; 
    948953            if (start_y - 2 >= count) { 
  • src/file.c

    diff --git a/src/file.c b/src/file.c
    index a19633a..8936e68 100644
    a b  
    6363#include "widget.h" 
    6464#include "wtools.h" 
    6565#include "background.h"         /* we_are_background */ 
     66#include "util.h" 
    6667 
    6768/* Needed for current_panel, other_panel and WTree */ 
    6869#include "dir.h" 
    copy_file_file (FileOpContext *ctx, const char *src_path, const char *dst_path, 
    791792            } 
    792793        } 
    793794 
    794         if (!appending) { 
     795        if (!appending && ctx->preserve) { 
    795796            while (mc_chmod (dst_path, (src_mode & ctx->umask_kill))) { 
    796797                temp_status = file_error ( 
    797798                        _(" Cannot chmod target file \"%s\" \n %s "), dst_path); 
    panel_operate (void *source_panel, FileOperation operation, 
    18721873                dest = temp2; 
    18731874                temp = NULL; 
    18741875 
     1876                source_with_path = unescape_string(source_with_path); 
     1877                dest = unescape_string(dest); 
    18751878                switch (operation) { 
    18761879                case OP_COPY: 
    18771880                    /* 
    panel_operate (void *source_panel, FileOperation operation, 
    19631966                else { 
    19641967                    char *temp2 = concat_dir_and_file (dest, temp); 
    19651968 
     1969                        source_with_path = unescape_string(source_with_path); 
     1970                        temp2 = unescape_string(temp2); 
     1971                         
    19661972                    switch (operation) { 
    19671973                    case OP_COPY: 
    19681974                        /* 
  • src/util.c

    diff --git a/src/util.c b/src/util.c
    index da6d1b2..b5a2927 100644
    a b Q_ (const char *s) 
    15251525    return (sep != NULL) ? sep + 1 : result; 
    15261526} 
    15271527 
     1528/* Unescape paths or other strings for e.g the internal cd  */ 
     1529char * 
     1530unescape_string ( const char * in ) { 
     1531        char * local = NULL; 
     1532        int i = 0; 
     1533        int j = 20; 
     1534        int k = 0; 
     1535 
     1536        local = g_malloc(j); 
     1537         
     1538        for (i=0;i<=strlen(in);i++) { 
     1539                if (i-k+1 >= j ) { 
     1540                        j = j + 20; 
     1541                        local = g_realloc(local,j); 
     1542                } 
     1543                if ( (strchr(" \t*|;<>~#()?[]{}&",in[i])) && ((i == 0) || ( strchr("\\",in[i-1]))) ) { 
     1544                        k++; 
     1545                        local[i-k] = in[i]; 
     1546                } else { 
     1547                        local[i-k] = in[i]; 
     1548                } 
     1549        } 
     1550        local[i-k] = '\0'; 
     1551         
     1552        return local; 
     1553} 
     1554 
     1555/* To be compatible with the general posix command lines we have to escape * 
     1556 * strings for the command line                                                                                    */ 
     1557char * 
     1558escape_string ( const char * in ) { 
     1559        char * local = NULL; 
     1560        int i = 0; 
     1561        int j = 20; 
     1562        int k = 0; 
     1563 
     1564        local = g_malloc(j); 
     1565 
     1566        for (i=0;i<strlen(in);i++) { 
     1567                if (i+k+1 >= j ) { //If 20 chars is too low for the path 
     1568                        j = j + 20; 
     1569                        local = g_realloc(local,j); 
     1570                } 
     1571                if ( (strchr(" \t*|;<>~#()?[]{}&",in[i])) && ((i == 0) || (! strchr("\\",in[i-1]))) ) { 
     1572                        local[i+k] = 92; // Ascii for "\" 
     1573                        k = k+1; 
     1574                        local[i+k] = in[i]; 
     1575                } else { 
     1576                        local[i+k] = in[i]; 
     1577                } 
     1578        } 
     1579        local[i+k] = '\0'; 
     1580 
     1581        return local; 
     1582} 
  • src/util.h

    diff --git a/src/util.h b/src/util.h
    index 4e9a113..9c69e99 100644
    a b extern char *str_unconst (const char *); 
    1414extern const char *cstrcasestr (const char *haystack, const char *needle); 
    1515extern const char *cstrstr (const char *haystack, const char *needle); 
    1616 
     17char *unescape_string ( const char * in ); 
     18char *escape_string ( const char * in ); 
    1719void str_replace(char *s, char from, char to); 
    1820int  is_printable (int c); 
    1921void msglen (const char *text, /*@out@*/ int *lines, /*@out@*/ int *columns);