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,
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...
Hi @Paul Tiseo I need more information to help you with this. Could you post the Scripted Field code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
if(issue.getIssueType().getName() != 'Epic') {
return
}
UserManager userManager = ComponentAccessor.getUserManager()
ApplicationUser user = userManager.getUserByName('sysadmin')
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml
if (issue.getIssueType().getName() != 'Epic') {
return
}
UserManager userManager = ComponentAccessor.getUserManager()
ApplicationUser user = userManager.getUserByName('sysadmin')
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
Collection<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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.