Ensure that stomp-read-frame returns nil for incomplete frames

master
Hugo Thunnissen 6 years ago
parent 138733ef05
commit 4422553506

@ -26,7 +26,7 @@
(defun stomp-send-frame (process frame)
"Send a message to a STOMP process"
(process-send-string process (stomp-frame-to-string frame)))
(defun stomp-filter-function (callback)
"Filter function to be used with processes"
(unless (functionp callback) (signal 'wrong-type-argument 'functionp))
@ -69,10 +69,11 @@
((and headers-end-point)
(map-put frame 'command (current-word))
(map-put frame 'headers (stomp-read-headers buffer headers-end-point))
(map-put frame 'content
(buffer-substring
(+ 1 headers-end-point)
(stomp-find-frame-end-point buffer frame headers-end-point))))
(let ((frame-end-point (stomp-find-frame-end-point buffer frame headers-end-point)))
(if frame-end-point
(map-put frame 'content (buffer-substring (+ 1 headers-end-point) frame-end-point))
nil)))
(t nil)))))
(defun stomp-read-headers (buffer end-point &optional headers)
@ -96,16 +97,18 @@
either by using the content-length header or by searching for
the null octet."
(with-current-buffer buffer
(let ((content-length (stomp-frame-header "content-length" frame))
(headers-end-point(if headers-end-point
headers-end-point
(stomp-find-headers-end-point buffer))))
(if content-length
(+ headers-end-point 1 (string-to-number content-length))
(progn
(goto-char (point-min))
(search-forward-regexp "\u0000\\|\u0000\r")
(- (point) 1))))))
(let* ((content-length (stomp-frame-header "content-length" frame))
(headers-end-point
(if headers-end-point headers-end-point (stomp-find-headers-end-point buffer)))
(end-point (if content-length
(+ headers-end-point 1 (string-to-number content-length))
(progn
(goto-char (point-min))
(search-forward-regexp "\u0000\\|\u0000\r" nil t)
(- (point) 1)))))
(if (or (> end-point (point-max)) (<= end-point 0))
nil
end-point))))
(defun stomp-find-headers-end-point (buffer)
"Find the end of the header part of a STOMP frame."

@ -60,6 +60,23 @@
("content-length" . "11"))))
(should (equal (alist-get 'content recieved) "jwe\u0000jsiwli\u0000"))))
(ert-deftest returns-nil-when-incomplete-frame ()
"When there is no complete frame at the top of a buffer, read-frame
should return nil"
(with-testing-buffer
"incomplete_frame.txt"
(setq recieved (stomp-read-frame (current-buffer)))
(should (equal recieved nil))))
(ert-deftest returns-nil-when-incomplete-frame-no-headers ()
"When no 'end of headers' marker can be found, stomp-read-frame should return nil"
(with-testing-buffer
"incomplete_frame_no_headers.txt"
(setq recieved (stomp-read-frame (current-buffer)))
(should (equal nil recieved))))
(ert-deftest can-delete-one-frame ()
"Can delete the topmost frame in a buffer"
(with-testing-buffer

@ -0,0 +1,3 @@
MESSAGE
not-complete:nope
Loading…
Cancel
Save