bugGNUstep - Bugs: bug #35685, NSString fails to decode uppercase...

Group
 
 

bug #35685: NSString fails to decode uppercase percent-escapes [PATCHED]

Submitter:  Jens Alfke <snej>
Submitted:  Thu 01 Mar 2012 11:18:37 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 02 Mar 2012 07:18:58 AM UTC, comment #1: 

Thanks ... I applied that fix

Richard Frith-Macdonald <CaS>
Group Member
Thu 01 Mar 2012 11:18:37 PM UTC, original submission:  

-[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;
      }

Jens Alfke <snej>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by snej (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-03-02 CaS StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code