Skip to content

Commit

Permalink
[FIXED JENKINS-16974] Unsafe to define a function in <script> without…
Browse files Browse the repository at this point in the history
… a generated name, as it could clash with functions defined in unrelated *.jelly that happen to included in the same page.
  • Loading branch information
jglick committed Jun 11, 2013
1 parent 609c4f8 commit 3c01366
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
“Build Now” link did not work for multijobs.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16974">issue 16974</a>)
<li class=bug>
“Projects tied to slave” shows unrelated Maven module jobs.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17451">issue 17451</a>)
Expand Down
Expand Up @@ -45,10 +45,11 @@ THE SOFTWARE.
</l:task>
<j:if test="${it.configurable}">
<j:if test="${it.buildable}">
<j:set var="id" value="${h.generateId()}"/>
<l:task icon="images/24x24/clock.png" href="${url}/build?delay=0sec" title="${it.buildNowText}"
onclick="${it.parameterized?null:'return build(this)'}" post="${!it.parameterized}" permission="${it.BUILD}"/>
onclick="${it.parameterized?null:'return build_' + id + '(this)'}" post="${!it.parameterized}" permission="${it.BUILD}"/>
<script>
function build(a) {
function build_${id}(a) {
new Ajax.Request(a.href);

hoverNotification('${%Build scheduled}',a.parentNode);
Expand Down
Expand Up @@ -26,6 +26,7 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<td>
<j:if test="${job.buildable and job.hasPermission(job.BUILD)}">
<j:set var="id" value="${h.generateId()}"/>
<a href="${jobBaseUrl}${job.shortUrl}build?delay=0sec">
<j:choose>
<j:when test="${job.parameterized}">
Expand All @@ -36,13 +37,13 @@ THE SOFTWARE.
<j:otherwise>
<img src="${imagesURL}/${subIconSize}/clock.png"
title="${%Schedule a build}" alt="${%Schedule a build}"
onclick="return build(this)"
onclick="return build_${id}(this)"
border="0"/>
</j:otherwise>
</j:choose>
</a>
<script>
function build(img) {
function build_${id}(img) {
new Ajax.Request(img.parentNode.href);
hoverNotification('${%Build scheduled}', img, -100);
return false;
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/resources/lib/layout/confirmationLink.jelly
Expand Up @@ -38,9 +38,10 @@ THE SOFTWARE.
A confirmation dialog message.
</st:attribute>
</st:documentation>
<a href="#" onclick="confirmPOST(${post ?: 'false'}, '${attrs.href}', '${h.jsStringEscape(message)}')"><d:invokeBody/></a>
<j:set var="id" value="${h.generateId()}"/>
<a href="#" onclick="confirmPOST_${id}(${post ?: 'false'}, '${attrs.href}', '${h.jsStringEscape(message)}')"><d:invokeBody/></a>
<script>
function confirmPOST(post, href, message) {
function confirmPOST_${id}(post, href, message) {
if (confirm(message)) {
var form = document.createElement('form');
form.setAttribute('method', post ? 'POST' : 'GET');
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/resources/lib/layout/task.jelly
Expand Up @@ -115,9 +115,10 @@ THE SOFTWARE.
<j:set var="icon" value="${rootURL}${icon.startsWith('images/') || icon.startsWith('plugin/') ? h.resourcePath : ''}/${icon}"/>
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(href, icon, title, post == 'true', requiresConfirmation == 'true') : null}

<j:set var="id" value="${h.generateId()}"/>
<j:if test="${attrs.onclick == null and post and not requiresConfirmation}">
<script>
function postRequest(a) {
function postRequest_${id}(a) {
new Ajax.Request(a.href);
hoverNotification('${%Done.}', a.parentNode);
return false;
Expand All @@ -132,7 +133,7 @@ THE SOFTWARE.
</l:confirmationLink>
</j:when>
<j:otherwise>
<a href="${href}" onclick="${attrs.onclick ?: (post ? 'postRequest(this)' : null)}">
<a href="${href}" onclick="${attrs.onclick ?: (post ? 'postRequest_' + id + '(this)' : null)}">
<img width="24" height="24" style="margin: 2px;" alt="" src="${icon}"/>
</a>
</j:otherwise>
Expand All @@ -153,7 +154,7 @@ THE SOFTWARE.
</l:confirmationLink>
</j:when>
<j:otherwise>
<a href="${href}" onclick="${attrs.onclick ?: (post ? 'postRequest(this)' : null)}">
<a href="${href}" onclick="${attrs.onclick ?: (post ? 'postRequest_' + id + '(this)' : null)}">
<j:choose>
<j:when test="${match}">
<b>${title}</b>
Expand Down

0 comments on commit 3c01366

Please sign in to comment.