I have a scripted field where I display the Summary. If the Summary has a doubel-quote, my display breaks. How do I HTML encode the string? (Sorry, but not sure how to do this in Groovy in this constrained script engine environment.)
Hi @Paul Tiseo I need more information to help you with this. Could you post the Scripted Field code?
Hi @Paul Tiseo,
As @Alejandro Suárez García suggested, please post your code.
Also please mention your Jira version and ScriptRunner version.
I tried and everything works fine...
In the code below, the problem is in the linkedIssue.getSummary() being added to the title tag in an HTML field. If the Summary has a double-quote, it prematurely ends the attribute's value. I should probably just do a replace, but I was wondering how to HTML encode if I needed to.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.link.IssueLinkManagerimport com.atlassian.jira.user.util.UserManagerimport com.atlassian.jira.user.ApplicationUserif(issue.getIssueType().getName() != 'Epic') { return}UserManager userManager = ComponentAccessor.getUserManager()ApplicationUser user = userManager.getUserByName('sysadmin')IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManagerdef linkedIssues = issueLinkManager.getLinkCollection(issue, user, false).getAllIssues()def sb = new StringBuilder()for (linkedIssue in linkedIssues) { if (!linkedIssue.getResolution()) { sb <<= '<span style="white-space: nowrap"><a href="https://projects.jtafla.com/browse/' sb <<= linkedIssue.getKey() sb <<= '" title="Summary: ' sb <<= linkedIssue.getSummary() sb <<= '\nType: ' sb <<= linkedIssue.getIssueType().getName() sb <<= '\nAssignee: ' sb <<= linkedIssue.getAssignee() sb <<= '\nResolution: ' sb <<= linkedIssue.getResolution() sb <<= '">' sb <<= linkedIssue.getKey() sb <<= '</a> (' sb <<= linkedIssue.getStatus().getName() sb <<= ')</span><br />' }}return sb
Hi @Paul Tiseo, you can escape that quotes in java with the "org.apache.commons.lang.StringEscapeUtils.escapeHtml" class.
Here is the code:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.link.IssueLinkManagerimport com.atlassian.jira.user.util.UserManagerimport com.atlassian.jira.user.ApplicationUserimport static org.apache.commons.lang.StringEscapeUtils.escapeHtmlif (issue.getIssueType().getName() != 'Epic') {return}UserManager userManager = ComponentAccessor.getUserManager()ApplicationUser user = userManager.getUserByName('sysadmin')IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManagerCollection<Issue> linkedIssues = issueLinkManager.getLinkCollection(issue, user, false).getAllIssues()StringBuilder sb = new StringBuilder()linkedIssues.findAll { !it.getResolution() }.each { Issue linkedIssue -> sb <<= '<span style="white-space: nowrap"><a href="https://projects.jtafla.com/browse/' sb <<= linkedIssue.getKey() sb <<= '" title="Summary: ' sb <<= escapeHtml(linkedIssue.getSummary()) sb <<= '\nType: ' sb <<= linkedIssue.getIssueType().getName() sb <<= '\nAssignee: ' sb <<= linkedIssue.getAssignee() sb <<= '\nResolution: ' sb <<= linkedIssue.getResolution() sb <<= '">' sb <<= linkedIssue.getKey() sb <<= '</a> (' sb <<= linkedIssue.getStatus().getName() sb <<= ')</span><br />'}return sb
@Paul TiseoAditionally if you want to display only the assignee "Display Name" you have to replace
linkedIssue.getAssignee()
for:
linkedIssue.getAssignee()?.getDisplayName()
This way if the variable returns null it'll display null but if assignee have an user it will display only the Full Name.
Hope it helps!
Regards
It looks like you're new here. Sign in or register to get started.