0

I have a JSP which is used to display location in UI form where JSTL code is been used,

function setLocation() {
      var fullPath = "${fn:escapeXml(folderPath)}";
      updateFolderPath(fullPath);
    
  }

the folderPath value is "university_stores\university" which is coming from form, but fn:escapeXml is failing and giving "Uncaught SyntaxError: Invalid Unicode escape sequence" as fullPath is becoming "university_stores\university" after the escapeXml function is executed and jsp gets loaded to UI

Can someone help me to fix this issue or is there any ulternate I can use for escapeXml, I tried splitting the string and concating again but didnt worked

Jens
  • 67,715
  • 15
  • 98
  • 113
Ram Somani
  • 231
  • 3
  • 12
  • Hi, JavaScript != XML. You need to escape for JavaScript, not for XML :) See abovelinked duplicate. – BalusC Nov 13 '22 at 13:18
  • @BalusC I tried this var fullPath = "<%= org.apache.commons.lang3.StringEscapeUtils.escapeEcmaScript((String) folderPath) %>"; but it is giving error saying folderPath is not defined but I have folderPath as a var in the function var folderPath = getForm().folderPath.value; Can you tell me how to add a folderPath to escapeEcmaScript function – Ram Somani Nov 13 '22 at 17:20
  • Simply use `${...}` as instructed in the abovelinked duplicate instead of old fashioned `<%...%>` practice of previous century. – BalusC Nov 13 '22 at 17:55
  • @BalusC okay it worked but my question is that functionality wise escapeXml and escapeEcmaScript same like when we use esacpeXml and if it encounters any value like <,>,& it replaces to '<': return '<';'>': return '>';'&': return '&';'\'': return ''';'"': return '"'; will escapeEcmaScript will do the same thing? – Ram Somani Nov 14 '22 at 08:10

0 Answers0