bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Jens Alfke
Subject: [bug #35685] NSString fails to decode uppercase percent-escapes [PATCHED]
Date: Thu, 01 Mar 2012 23:18:38 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.22 (KHTML, like Gecko) Chrome/19.0.1049.3 Safari/535.22

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]