Closed ovenpasta closed 9 years ago
Thank you @ovenpasta This needs a fix. Having a couple of hectic weeks here. But I think a good way to start is to add a bunch of tests to sack. Spheres' libraries are ready for that next step at the moment.
the problem is with (check-arg (lambda (len) (fx> len 0)) len 'utf-u8vector->string "The input u8vector is not proper UTF-8.") in spheres/u8vector.scm. a possible fix maybe allowing to have a (fx>= 0 len) vector (to me seems reasonable) or fixing it in net/sack/url.scm like this:
diff --git a/spheres/net/sack/uri.scm b/spheres/net/sack/uri.scm
index 792856f..6ea5fc1 100644
--- a/spheres/net/sack/uri.scm
+++ b/spheres/net/sack/uri.scm
@@ -377,7 +377,9 @@
(loop (+ i 1)
(+ j 1)))))
;; result now contains the u8vector with the extracted bytes, so let's UTF8-decode them.
- (utf8-u8vector->string result)))))
+ (if (fx> (u8vector-length result) 0)
+ (utf8-u8vector->string result)
+ "")))))
;; Extract a substring out of a URI / URI component string, depending on current decoding settings.
;;
I think this is the solution anyway :)
diff --git a/spheres/string/u8vector.scm b/spheres/string/u8vector.scm
index 71c0457..3147e87 100644
--- a/spheres/string/u8vector.scm
+++ b/spheres/string/u8vector.scm
@@ -139,7 +139,7 @@
1)))))))
;; It could be that we get a negative length because the string was very short and ended
;; with only the first 1-2 bytes of a 2-3 byte multibyte UTF-8 character.
- (check-arg (lambda (len) (fx> len 0)) len 'utf-u8vector->string "The input u8vector is not proper UTF-8.")
+ (check-arg (lambda (len) (fx>= len 0)) len 'utf-u8vector->string "The input u8vector is not proper UTF-8.")
;; (print "output string length = " len " (u8vector length=" u8v-len ")\n")
;; Compiled with (declare (safe))
(let ((s (make-string len)))
Great! Can you open a PR please?
I've found a bug in Sack, the procedure string->uri is not handling empty values example:
the result is that the request hangs