Commits

Anonymous committed a8ae5fa

don't escape digits in String.urlencode; inlined Buffer.add_char

Comments (0)

Files changed (1)

src/cd_Strings.ml

         value urlencode s =
           let len = String.length s in
           let buf = Buffer.create len in
-          let out ch =
-            Buffer.add_char buf ch
-          in
           let out_esc ch =
             let c = Char.code ch in
-            ( out '%'
-            ; out hex_digits.[c lsr 4]
-            ; out hex_digits.[c land 0x0F]
+            ( Buffer.add_char buf '%'
+            ; Buffer.add_char buf hex_digits.[c lsr 4]
+            ; Buffer.add_char buf hex_digits.[c land 0x0F]
             )
           in
           let rec loop i =
                 match s.[i] with
                 [   'a' .. 'z'
                   | 'A' .. 'Z'
+                  | '0' .. '9'
                   | '-' | '.' | '_' | '~'
                   as ch
                     ->
-                      out ch
+                      Buffer.add_char buf ch
                 | ch ->
                       out_esc ch
                 ]