diff --git a/jabber-core.el b/jabber-core.el index de05a34..9258647 100644 --- a/jabber-core.el +++ b/jabber-core.el @@ -899,10 +899,7 @@ DATA is any sexp." (while (search-forward-regexp " \\w+=''" nil t) (replace-match ""))) - (setq xml-data (and (catch 'unfinished - (jabber-xml-skip-tag-forward) - (> (point) (point-min))) - (xml-parse-region (point-min) (point)))) + (setq xml-data (jabber-xml-parse-next-stanza)) while xml-data do diff --git a/jabber-xml.el b/jabber-xml.el index e19a247..520f033 100644 --- a/jabber-xml.el +++ b/jabber-xml.el @@ -133,6 +133,17 @@ enough for us." (t (throw 'unfinished nil)))) +(defun jabber-xml-parse-next-stanza () + "Parse the first XML stanza in the current buffer. +Parse and return the first complete XML element in the buffer, +leaving point at the end of it. If there is no complete XML +element, return `nil'." + (and (catch 'unfinished + (goto-char (point-min)) + (jabber-xml-skip-tag-forward) + (> (point) (point-min))) + (xml-parse-region (point-min) (point)))) + (defsubst jabber-xml-node-name (node) "Return the tag associated with NODE. The tag is a lower-case symbol." diff --git a/tests/Makefile.am b/tests/Makefile.am index 8575ddb..e171536 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,5 +2,5 @@ # check" or "make distcheck" to work with earlier versions. LOG_COMPILER = env top_builddir=$(top_builddir) $(EMACS) -batch -L $(top_builddir) -L $(top_srcdir) -L $(srcdir) -l TESTS = load-all.el skip-tag-forward.el history.el jabberd.el nick-change-fail.el -TESTS += caps-hash.el +TESTS += caps-hash.el parse-next-stanza.el dist_noinst_DATA = $(TESTS) diff --git a/tests/parse-next-stanza.el b/tests/parse-next-stanza.el new file mode 100644 index 0000000..d4f57b0 --- /dev/null +++ b/tests/parse-next-stanza.el @@ -0,0 +1,18 @@ +;; Tests for jabber-xml-parse-next-stanza + +(require 'jabber-xml) + +(defun parse-it (text) + (with-temp-buffer + (insert text) + (jabber-xml-parse-next-stanza))) + +(unless (equal + (parse-it "") + '((presence ((from . "foo@example.com/resource") (type . "unavailable") (to . "bar@example.com"))))) + (error "Testcase 1 failed")) + +(unless (equal + (parse-it "