I am facing an issue with a cycle in a jspx file that I have. The cycle looks like this:
<c:forEach var="var" items="${dataFile.list.rows}">
<li>
<div>
<a href="#" onClick="myFunct('${var.url}','escape(${var.title}),'escape(${var.descr})');">
<img width="108" height="66" alt="" src="${var.img}" />
</a>
</div>
</li>
</c:forEach>
The problem arises when the variables ${var.title}
or ${var.descr}
contain quotes or double quotes. It is difficult to handle these cases as I cannot predict the type of quote that will be present.
I have tried different approaches, such as using a helper JavaScript section before the element, but without knowing the type of quotes in advance, it is challenging to decide whether to use escape("${var.title}")
or escape('${var.title}')
.
If you have any ideas on how to solve this issue, please let me know. Thank you.