1. Dmitry Grebeniuk
  2. cadastr

Commits

Dmitry Grebeniuk  committed a8ae5fa

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

  • Participants
  • Parent commits 36e69a5
  • Branches default

Comments (0)

Files changed (1)

File src/cd_Strings.ml

View file
         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
                 ]