URL: <http://savannah.gnu.org/bugs/?35685>
Summary: NSString fails to decode uppercase percent-escapes [PATCHED] Project: GNUstep Submitted by: snej Submitted on: Thu 01 Mar 2012 11:18:37 PM GMT Category: Base/Foundation Severity: 3 - Normal Item Group: Bug Status: None Privacy: Public Assigned to: None Open/Closed: Open Discussion Lock: Any _______________________________________________________ Details: -[NSString stringByReplacingPercentEscapesUsingEncoding:] returns nil when given a validly URL-escaped string that uses uppercase hex digits in its escapes. TEST CASE: assert([@"foo%2Fbar" stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding] != nil); DIAGNOSIS There's a nasty little bug in the hex digit decoding in that method implementation. It checks for an uppercase letter by comparing "t <= 'A'" instead of "t <= 'F'". I searched the source tree for other cases where this bad code might have been pasted, and found another one in NSURL's initializer. I fixed it too (see patch). PATCH: Index: NSString.m =================================================================== --- NSString.m (revision 34837) +++ NSString.m (working copy) @@ -4128,7 +4128,7 @@ { c = t - '0'; } - else if (t <= 'A') + else if (t <= 'F') { c = t - 'A' + 10; } @@ -4156,7 +4156,7 @@ { c |= t - '0'; } - else if (t <= 'A') + else if (t <= 'F') { c |= t - 'A' + 10; } Index: NSURL.m =================================================================== --- NSURL.m (revision 34837) +++ NSURL.m (working copy) @@ -1013,7 +1013,7 @@ { c = *str - '0'; } - else if (*str <= 'A') + else if (*str <= 'F') { c = *str - 'A' + 10; } @@ -1027,7 +1027,7 @@ { c |= *str - '0'; } - else if (*str <= 'A') + else if (*str <= 'F') { c |= *str - 'A' + 10; } _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?35685> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/ _______________________________________________ Bug-gnustep mailing list Bug-gnustep@gnu.org https://lists.gnu.org/mailman/listinfo/bug-gnustep