Changeset 12140 in project


Ignore:
Timestamp:
10/12/08 22:55:29 (12 years ago)
Author:
sjamaan
Message:

Merge changes from uri-generic for chicken 3

Location:
release/4/uri-generic/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/uri-generic/trunk

  • release/4/uri-generic/trunk/tests/run.scm

    r11826 r12140  
    136136                  )))
    137137            extra-cases))
     138
     139(define encode/decode-cases
     140  '(("foo?bar" "foo%3fbar")
     141    ("foo&bar" "foo%26bar")
     142    ("foo%20bar" "foo%2520bar")))
     143
     144(test-group "uri-encode-string test"
     145  (for-each (lambda (p)
     146              (let ((expected (second p))
     147                    (encoded (uri-encode-string (first p))))
     148                  (test (sprintf "~S -> ~S" (first p) expected) expected encoded)))
     149            encode/decode-cases))
     150
     151(test-group "uri-decode-string test"
     152  (for-each (lambda (p)
     153              (let ((expected (first p))
     154                    (decoded (uri-decode-string (second p))))
     155                  (test (sprintf "~S -> ~S" (second p) expected) expected decoded)))
     156            encode/decode-cases))
  • release/4/uri-generic/trunk/uri-generic.scm

    r12004 r12140  
    702702   (fold (lambda (c ax)
    703703           (if (p c) (let* ((os (enc c)) 
    704                             (cs (map pct-encode os)))
    705                        (append (concatenate (reverse cs)) ax))
     704                            (cs (pct-encode os)))
     705                       (append (reverse cs) ax))
    706706               (cons c ax)))
    707707         (list) str)))
     
    712712        (loop (quotient i 256) (cons (modulo i 256) lst)))))
    713713
     714(define (pct? c) (char=? c #\%))
    714715
    715716(define (uri-encode-string str)
    716   (let ((clst (uri-string->char-list str)))
    717     (uri-char-list->string 
    718      (char-list-encode reserved-char? (compose integer->octets char->integer) clst))))
     717  (let ((clst (string->list str)))
     718    (uri-char-list->string
     719     (char-list-encode (disjoin pct? reserved-char?) (compose integer->octets char->integer) clst))))
    719720
    720721
Note: See TracChangeset for help on using the changeset viewer.