date.lisp error not handled

8 views
Skip to first unread message

Fred

unread,
Dec 8, 2012, 3:10:47 PM12/8/12
to webl...@googlegroups.com
Hello,

the date parser of weblocks can failed if wrong numbers are used for the day, the month, the hours or the minutes.

The date parser use the encode-universal-time function wich throws an error (SIMPLE-TYPE-ERROR)
if, for example, the day number is grower than 31.

The result in weblocks is the well known alert popup :  'Oops, we could not complete your request because of an internal error.'

So , i have modified the date.lisp code to handle error :

(defun date->utime (day month year hour minute)
  (encode-universal-time 0 minute hour day month year))

(defmethod parse-view-field-value ((parser date-parser) value obj
                                   (view form-view) (field form-view-field) &rest args)
  (declare (ignore args))
  (if (text-input-present-p value)
      (multiple-value-bind (matched elements)
          (cl-ppcre:scan-to-strings "(\\d+)[\\-/\\.](\\d+)[\\-/\\.](\\d+)(\\s+(\\d+)[:\\.](\\d+))?" value)
        (when matched
+  (handler-case
          (let ((date (date->utime (parse-integer (aref elements 2) :junk-allowed t)
                                   (parse-integer (aref elements 1) :junk-allowed t)
                                   (parse-integer (aref elements 0) :junk-allowed t)
                                   (or (and (aref elements 4) (parse-integer (aref elements 4) :junk-allowed t)) 0)
                                   (or (and (aref elements 5) (parse-integer (aref elements 5) :junk-allowed t)) 0))))
            (when date (values t t date)))
+  (t () nil))))
      (values t (text-input-present-p value) value)))


Maybe it's not the right approach ?
What do you think about this ?

Thnaks.

Regards

Reply all
Reply to author
Forward
0 new messages