mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Fix bug in code for unescapiong strings - when not in unescape_special mode, quotes would not get properly removed. This patch also adds the ability to check that quotes match up when unescaping. This functionality is on by default and can be disabled using a special flag.
darcs-hash:20070118160246-ac50b-b230c3fcd8440025b5243d76de2a9fd400f7ea32.gz
This commit is contained in:
parent
19e8d60179
commit
9e7094adfc
2 changed files with 23 additions and 2 deletions
21
common.c
21
common.c
|
@ -791,7 +791,7 @@ wchar_t *escape( const wchar_t *in,
|
|||
}
|
||||
|
||||
|
||||
wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
||||
wchar_t *unescape( const wchar_t * orig, int flags )
|
||||
{
|
||||
|
||||
int mode = 0;
|
||||
|
@ -800,7 +800,9 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
int bracket_count=0;
|
||||
wchar_t prev=0;
|
||||
wchar_t *in;
|
||||
|
||||
int unescape_special = flags & UNESCAPE_SPECIAL;
|
||||
int allow_incomplete = flags & UNESCAPE_INCOMPLETE;
|
||||
|
||||
CHECK( orig, 0 );
|
||||
|
||||
len = wcslen( orig );
|
||||
|
@ -1153,6 +1155,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
mode = 1;
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1161,6 +1165,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
mode = 2;
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1209,6 +1215,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
{
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
mode = 0;
|
||||
}
|
||||
else
|
||||
|
@ -1231,6 +1239,8 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
mode = 0;
|
||||
if( unescape_special )
|
||||
in[out_pos] = INTERNAL_SEPARATOR;
|
||||
else
|
||||
out_pos--;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1287,6 +1297,13 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !allow_incomplete && mode )
|
||||
{
|
||||
free( in );
|
||||
return 0;
|
||||
}
|
||||
|
||||
in[out_pos]=L'\0';
|
||||
return in;
|
||||
}
|
||||
|
|
4
common.h
4
common.h
|
@ -40,6 +40,10 @@
|
|||
*/
|
||||
#define BYTE_MAX 0xffu
|
||||
|
||||
#define UNESCAPE_SPECIAL 1
|
||||
#define UNESCAPE_INCOMPLETE 2
|
||||
|
||||
|
||||
/**
|
||||
Save the shell mode on startup so we can restore them on exit
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue