bug 228176 exclude control characters from unescaping URLs for the UI : r=darin, sr=jst

This commit is contained in:
jshin%mailaps.org 2004-01-07 03:57:20 +00:00
parent 5abc73e899
commit 8ea11801c8
3 changed files with 18 additions and 9 deletions

View File

@ -228,8 +228,10 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString & aCharset,
const nsACString &aURIFragment,
nsAString &_retval)
{
nsCAutoString unescapedSpec(aURIFragment);
NS_UnescapeURL(unescapedSpec);
nsCAutoString unescapedSpec;
// exclude control octets (0x00 - 0x1f and 0x7f) from unescaping
NS_UnescapeURL(PromiseFlatCString(aURIFragment),
esc_ExcludeControl | esc_AlwaysCopy, unescapedSpec);
return convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec, PR_TRUE, _retval);
}

View File

@ -385,11 +385,11 @@ NS_COM PRBool NS_EscapeURL(const char *part,
//
// And, we will not escape non-ascii characters if requested.
// On special request we will also escape the colon even when
// not covered by the matrix
// not covered by the matrix.
// ignoreAscii is not honored for control characters (C0 and DEL)
if ((NO_NEED_ESC(c) || (c == HEX_ESCAPE && !forced)
|| (c > 0x7f && ignoreNonAscii)
|| (c < 0x80 && ignoreAscii))
|| (c > 0x1f && c < 0x7f && ignoreAscii))
&& !(c == ':' && colon))
{
if (writing)
@ -436,6 +436,7 @@ NS_COM PRBool NS_UnescapeURL(const char *str, PRInt32 len, PRInt16 flags, nsACSt
PRBool ignoreNonAscii = (flags & esc_OnlyASCII);
PRBool writing = (flags & esc_AlwaysCopy);
PRBool excludeControl = (flags & esc_ExcludeControl);
static const char hexChars[] = "0123456789ABCDEFabcdef";
@ -447,7 +448,9 @@ NS_COM PRBool NS_UnescapeURL(const char *str, PRInt32 len, PRInt16 flags, nsACSt
if (*p == HEX_ESCAPE && i < len-2) {
unsigned char *p1 = ((unsigned char *) p) + 1;
unsigned char *p2 = ((unsigned char *) p) + 2;
if (ISHEX(*p1) && ISHEX(*p2) && !(ignoreNonAscii && *p1 >= '8')) {
if (ISHEX(*p1) && ISHEX(*p2) && !(ignoreNonAscii && *p1 >= '8') &&
!(excludeControl &&
(*p1 < '2' || (*p1 == '7' && (*p2 == 'f' || *p2 == 'F'))))) {
//printf("- p1=%c p2=%c\n", *p1, *p2);
writing = PR_TRUE;
if (p > last) {

View File

@ -105,9 +105,12 @@ enum EscapeMask {
esc_Minimal = esc_Scheme | esc_Username | esc_Password | esc_Host | esc_FilePath | esc_Param | esc_Query | esc_Ref,
esc_Forced = PR_BIT(10), /* forces escaping of existing escape sequences */
esc_OnlyASCII = PR_BIT(11), /* causes non-ascii octets to be skipped */
esc_OnlyNonASCII = PR_BIT(12), /* causes ascii octets to be skipped */
esc_OnlyNonASCII = PR_BIT(12), /* causes _graphic_ ascii octets (0x20-0x7E)
* to be skipped when escaping. causes all
* ascii octets to be skipped when unescaping */
esc_AlwaysCopy = PR_BIT(13), /* copy input to result buf even if escaping is unnecessary */
esc_Colon = PR_BIT(14) /* force escape of colon */
esc_Colon = PR_BIT(14), /* forces escape of colon */
esc_ExcludeControl = PR_BIT(15) /* excludes C0 and DEL from unescaping */
};
/**
@ -134,7 +137,8 @@ NS_COM PRBool NS_EscapeURL(const char *str,
*
* @param str url string to unescape
* @param len length of |str|
* @param flags only esc_OnlyNonASCII and esc_AlwaysCopy are recognized
* @param flags only esc_OnlyNonASCII, esc_ExcludeControl and esc_AlwaysCopy
* are recognized
* @param result result buffer, untouched if |str| is already unescaped
*
* @return TRUE if unescaping was performed, FALSE otherwise.