vtest "ESI parsing errors"

server s1 {
	rxreq
	txresp -body {
		<html>					1
		Before include				2
		<!--esi <esi:include src="/body"/> -->	3
		After include				4
		<!-- normal comment -->			5
		<esi:bogosity/>				6
		<esi:comment>				7
		 foo					8
		 </esi:comment>				9
		<esi:comment bar />			10
							11
		<esi:remove>				12
			<esi:comment foo/>		13
		</esi:remove>				14
							15
		<esi:remove>				16
			<esi:remove>			17
			bar				18
			</esi:remove>			19
		</esi:remove>				20
		</>					21
		<esi:remove/>				22
							23
		<esi:include				24
	

						     >	25
							26
		<esi:include  aaa />			27
		<esi:include  k?=./>			28
		<esi:include  src/>			29
		<esi:include  src=/>			30
		<esi:include  src= />			31
		</esi:include>				32
		<!---->					33
		</!-- bogocommentt -->			34
		</![CDATA[ bogo-cdata ]]>		35
		<esi:include  src="foofof />		36
		<esi:include  foo=bar src=/body2 />	37
		<esi:include  src="/body 2" />		38
	}
	rxreq
	expect req.url == "/body"
	txresp -body {
		<pre>Included file</pre>
		<esi:remove>
		<Aaa
	}
	rxreq
	expect req.url == "/body2"
	txresp -body {
		<pre>Included file 2</pre>
		<!--esi
		<![CDATA[fooo
	}
} -start

vinyl v1 -vcl+backend {
	sub vcl_backend_response {
		set beresp.do_esi = true;
	}
} -start

logexpect l1 -v v1 -g vxid {
	expect * * BereqURL	{^/$}
	expect * * ESI_xmlerror {^ERR: after 134 ESI 1.0 <esi:bogus> element$}
	expect 0 = ESI_xmlerror {^ERR: after 157 ESI 1.0 <esi:comment> needs final '/'$}
	expect 0 = ESI_xmlerror {^ERR: after 192 ESI 1.0 </esi:comment> illegal end-tag$}
	expect 0 = ESI_xmlerror {^ERR: after 251 ESI 1.0 <esi:comment> element nested in <esi:remove>$}
	expect 0 = ESI_xmlerror {^ERR: after 330 ESI 1.0 <esi:remove> already open$}
	expect 0 = ESI_xmlerror {^ERR: after 407 ESI 1.0 <esi:remove> not open$}
	expect 0 = ESI_xmlerror {^ERR: after 442 ESI 1.0 <esi:remove/> not legal$}
	expect 0 = ESI_xmlerror {^ERR: after 474 XML 1.0 Illegal attribute start char$}
	expect 0 = ESI_xmlerror {^ERR: after 525 ESI 1.0 <esi:include> lacks src attr$}
	expect 0 = ESI_xmlerror {^ERR: after 553 XML 1.0 Illegal attr char$}
	expect 0 = ESI_xmlerror {^ERR: after 581 ESI 1.0 <esi:include> lacks src attr$}
	expect 0 = ESI_xmlerror {^ERR: after 608 XML 1.0 Missing end attribute delimiter$}
	expect 0 = ESI_xmlerror {^ERR: after 636 XML 1.0 Illegal attribute delimiter$}
	expect 0 = ESI_xmlerror {^ERR: after 665 ESI 1.0 </esi:include> illegal end-tag$}
	expect 0 = ESI_xmlerror {^ERR: after 767 XML 1.0 Missing end attribute delimiter$}
	expect 0 = ESI_xmlerror {^ERR: after 843 ESI 1.0 <esi:include> has whitespace in src= attribute$}
	expect 0 = BackendClose
} -start

logexpect l2 -v v1 -g vxid {
	expect * * BereqURL	{^/body$}
	expect * = ESI_xmlerror {^ERR: after 30 VEP ended inside a tag$}
	expect 0 = BackendClose
} -start

logexpect l3 -v v1 -g vxid {
	expect * * BereqURL	{^/body2$}
	expect * = ESI_xmlerror {^ERR: after 39 VEP ended inside a tag$}
	expect 0 = BackendClose
} -start

vinyl v1 -cliok "param.set debug +esi_chop"

vinyl v1 -cliok "param.set debug +syncvsl"

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 472
}

client c1 -run
logexpect l1 -wait
logexpect l2 -wait
logexpect l3 -wait
vinyl v1 -expect esi_errors == 18
vinyl v1 -expect MAIN.s_resp_bodybytes == 472
