Making this customizable would be OK with me. The only problem I see is that the current pair of delimiters is hard-coded into the regexp and it's probably not a good idea to compute the regexp anew each time the function is called. I also think only paired delimiters like (), [], {}, <> really make sense. Any comments?
If you want to have this in Hunchentoot, please send a patch against the diff version following the usual guidelines:
Thanks, Edi.
2010/4/23 Knut Olav Bøhmer bohmer@gmail.com:
Hi,
When I post json objects from jquery
$.ajax({ type: 'POST', url: '/url', dataType: 'json', data: {"key":"val","hash",{"foo":"bar"}}
then the "hash" parameter is posted like this: "hash[foo]=bar"
If I then in hunchentoot have
(define-easy-handler (fn :uri "/url") ((hash :parameter-type 'hash-table)) .....
The hash is expected to be posted like this: "hash{foo}=bar"? So I wonder if it would be correct to enable the "hash[foo]=bar" syntax for hash tables.
Maybe it should be an argument that specifies if compute-hash-table-parameter should use [] or {}. This little experiment worked for me, here I just added \[ and \] to the regexp.
Should I bother to make a patch?
(defun compute-hash-table-parameter (parameter-name type parameters key-type test-function) "Retrieves all parameters from PARAMETERS which are named like "PARAMETER-NAME{FOO}" or "PARAMETER-NAME[FOO]" (where FOO is any sequence of characters not containing curly brackets), converts them to TYPE, and returns a hash table with test function TEST-FUNCTION where the corresponding value is associated with the key FOO (converted to KEY-TYPE)." (let ((hash-table (make-hash-table :test test-function))) (loop for (full-name . value) in parameters for key = (register-groups-bind (name key-string) ("^(.*)[{\[]([^\[\]{}]+)[}\]]$" full-name) (when (string= name parameter-name) (convert-parameter key-string key-type))) when key do (setf (gethash key hash-table) (convert-parameter value type))) hash-table))
-- Knut Olav Bøhmer
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel