unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] web: allow uri-encode to uppercase the percent-encoding
@ 2013-05-02 15:27 Aleix Conchillo Flaqué
  2013-05-03  1:00 ` Daniel Hartwig
  0 siblings, 1 reply; 3+ messages in thread
From: Aleix Conchillo Flaqué @ 2013-05-02 15:27 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 145 bytes --]

This patch allows uri-encode to uppercase the percent-encoded part. So,

(uri-encode "/")
=> %2f

(uri-encode "/" #:uppercase #t)
=> %2F


Aleix

[-- Attachment #2: uri-encode-uppercase.patch --]
[-- Type: application/octet-stream, Size: 3234 bytes --]

From 3aafc16880da953edfecbc5f3cc5445f9239ff59 Mon Sep 17 00:00:00 2001
From: Aleix Conchillo Flaque <aconchillo@gmail.com>
Date: Thu, 2 May 2013 08:21:21 -0700
Subject: [PATCH] web: allow uri-encode to uppercase the percent-encoding

* module/web/uri.scm (uri-encode): add an uppercase argument key to
  uppercase the percent-encoded hexadecimal characters. By default is
  set to false.
---
 module/web/uri.scm |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/module/web/uri.scm b/module/web/uri.scm
index 7fe0100..b4e3fe9 100644
--- a/module/web/uri.scm
+++ b/module/web/uri.scm
@@ -6,12 +6,12 @@
 ;;;; modify it under the terms of the GNU Lesser General Public
 ;;;; License as published by the Free Software Foundation; either
 ;;;; version 3 of the License, or (at your option) any later version.
-;;;; 
+;;;;
 ;;;; This library is distributed in the hope that it will be useful,
 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 ;;;; Lesser General Public License for more details.
-;;;; 
+;;;;
 ;;;; You should have received a copy of the GNU Lesser General Public
 ;;;; License along with this library; if not, write to the Free Software
 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,7 +20,7 @@
 ;;; Commentary:
 
 ;; A data type for Universal Resource Identifiers, as defined in RFC
-;; 3986. 
+;; 3986.
 
 ;;; Code:
 
@@ -374,6 +374,7 @@ ENCODING was ‘#f’."
 ;; transforming any characters not in UNESCAPED-CHARS.
 ;;
 (define* (uri-encode str #:key (encoding "utf-8")
+                     (uppercase #f)
                      (unescaped-chars unreserved-chars))
   "Percent-encode any character not in the character set,
 UNESCAPED-CHARS.
@@ -382,7 +383,8 @@ The default character set includes alphanumerics from ASCII, as well as
 the special characters ‘-’, ‘.’, ‘_’, and ‘~’.  Any other character will
 be percent-encoded, by writing out the character to a bytevector within
 the given ENCODING, then encoding each byte as ‘%HH’, where HH is the
-hexadecimal representation of the byte."
+hexadecimal representation of the byte. The percent-encoding can be
+uppercased if UPPERCASE is set to true."
   (define (needs-escaped? ch)
     (not (char-set-contains? unescaped-chars ch)))
   (if (string-index str needs-escaped?)
@@ -396,11 +398,13 @@ hexadecimal representation of the byte."
                        (len (bytevector-length bv)))
                   (let lp ((i 0))
                     (if (< i len)
-                        (let ((byte (bytevector-u8-ref bv i)))
+                        (let* ((byte (bytevector-u8-ref bv i))
+                               (num (number->string byte 16)))
                           (display #\% port)
                           (when (< byte 16)
                             (display #\0 port))
-                          (display (number->string byte 16) port)
+                          (display (if uppercase
+                                       (string-upcase num) num) port)
                           (lp (1+ i))))))))
           str)))
       str))
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] web: allow uri-encode to uppercase the percent-encoding
  2013-05-02 15:27 [PATCH] web: allow uri-encode to uppercase the percent-encoding Aleix Conchillo Flaqué
@ 2013-05-03  1:00 ` Daniel Hartwig
  2013-05-03  1:01   ` Daniel Hartwig
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Hartwig @ 2013-05-03  1:00 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué; +Cc: guile-devel

On 2 May 2013 23:27, Aleix Conchillo Flaqué <aconchillo@gmail.com> wrote:
> This patch allows uri-encode to uppercase the percent-encoded part. So,
>
> (uri-encode "/")
> => %2f
>
> (uri-encode "/" #:uppercase #t)
> => %2F

Hi

Why make this optional, it seems like unnecessary fluff?  Both cases
are equivalent, and RFC 3986 goes on to state:

> For consistency, URI producers and normalizers should use
> uppercase hexadecimal digits for all percent-encodings.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] web: allow uri-encode to uppercase the percent-encoding
  2013-05-03  1:00 ` Daniel Hartwig
@ 2013-05-03  1:01   ` Daniel Hartwig
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Hartwig @ 2013-05-03  1:01 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué; +Cc: guile-devel

On 3 May 2013 09:00, Daniel Hartwig <mandyke@gmail.com> wrote:
> On 2 May 2013 23:27, Aleix Conchillo Flaqué <aconchillo@gmail.com> wrote:
>> This patch allows uri-encode to uppercase the percent-encoded part. So,
>>
>> (uri-encode "/")
>> => %2f
>>
>> (uri-encode "/" #:uppercase #t)
>> => %2F
>
> Hi
>
> Why make this optional, it seems like unnecessary fluff?  Both cases
> are equivalent, and RFC 3986 goes on to state:
>

Should have read your next mail before responding :-)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-03  1:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-02 15:27 [PATCH] web: allow uri-encode to uppercase the percent-encoding Aleix Conchillo Flaqué
2013-05-03  1:00 ` Daniel Hartwig
2013-05-03  1:01   ` Daniel Hartwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).