@@ -701,6 +701,86 @@ public void queryPostXQueryError() throws IOException {
701701 }
702702 }
703703
704+ /**
705+ * See: <a href="https://github.com/eXist-db/exist/issues/5845">[BUG] Spurious namespace declarations in REST API results</a>
706+ */
707+ @ Test
708+ public void queryPostWithEnclosedExpressionResponseNamespaces () throws IOException {
709+ String query =
710+ "<query xmlns=\" http://exist.sourceforge.net/NS/exist\" wrap=\" no\" typed=\" no\" >\n " +
711+ " <text><doc>{3+4}</doc></text>\n " +
712+ "</query>" ;
713+
714+ HttpURLConnection connect = preparePost (query , getResourceUri ());
715+ try {
716+ connect .connect ();
717+ final int r = connect .getResponseCode ();
718+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
719+
720+ final String data = readResponse (connect .getInputStream ());
721+ assertEquals ("<doc>7</doc>" , data .trim ());
722+ } finally {
723+ connect .disconnect ();
724+ }
725+
726+ query =
727+ "<query xmlns=\" http://exist.sourceforge.net/NS/exist\" wrap=\" no\" typed=\" yes\" >\n " +
728+ " <text><doc>{3+4}</doc></text>\n " +
729+ "</query>" ;
730+
731+ connect = preparePost (query , getResourceUri ());
732+ try {
733+ connect .connect ();
734+ final int r = connect .getResponseCode ();
735+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
736+
737+ final String data = readResponse (connect .getInputStream ());
738+ assertEquals ("<doc>7</doc>" , data .trim ());
739+ } finally {
740+ connect .disconnect ();
741+ }
742+ }
743+
744+ /**
745+ * See: <a href="https://github.com/eXist-db/exist/issues/5845">[BUG] Spurious namespace declarations in REST API results</a>
746+ */
747+ @ Test
748+ public void queryPostWithoutEnclosedExpressionResponseNamespaces () throws IOException {
749+ String query =
750+ "<query xmlns=\" http://exist.sourceforge.net/NS/exist\" wrap=\" no\" typed=\" no\" >\n " +
751+ " <text><doc>7</doc></text>\n " +
752+ "</query>" ;
753+
754+ HttpURLConnection connect = preparePost (query , getResourceUri ());
755+ try {
756+ connect .connect ();
757+ final int r = connect .getResponseCode ();
758+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
759+
760+ final String data = readResponse (connect .getInputStream ());
761+ assertEquals ("<doc>7</doc>" , data .trim ());
762+ } finally {
763+ connect .disconnect ();
764+ }
765+
766+ query =
767+ "<query xmlns=\" http://exist.sourceforge.net/NS/exist\" wrap=\" no\" typed=\" yes\" >\n " +
768+ " <text><doc>7</doc></text>\n " +
769+ "</query>" ;
770+
771+ connect = preparePost (query , getResourceUri ());
772+ try {
773+ connect .connect ();
774+ final int r = connect .getResponseCode ();
775+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
776+
777+ final String data = readResponse (connect .getInputStream ());
778+ assertEquals ("<doc>7</doc>" , data .trim ());
779+ } finally {
780+ connect .disconnect ();
781+ }
782+ }
783+
704784 @ Test
705785 public void queryGet () throws IOException {
706786 final String uri = getCollectionUri ()
0 commit comments