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

 
 

You are not allowed to post comments on this tracker with your current authentication level.

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

Submitted by:  Jens Alfke <snej>
Submitted on:  Thu 01 Mar 2012 11:18:37 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

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

Thanks ... I applied that fix

Richard Frith-Macdonald <CaS>
Project 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>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 02 Mar 2012 07:18:58 AM UTCCaSStatusNone=>Fixed
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1