Skip to content

Commit

Permalink
Use ID if provided otherwise generate one
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jan 28, 2022
1 parent d56150d commit f25a406
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2290,8 +2290,9 @@ public static boolean isContextMenuVisible(Action a) {
}
}

@SuppressFBWarnings(value = "PREDICTABLE_RANDOM", justification = "True randomness isn't necessary for form item IDs")
@Restricted(NoExternalUse.class)
public static String generateItemId(String id) {
return Math.floor(Math.random() * 3000) + "-" + id;
public static String generateItemId() {
return String.valueOf(Math.floor(Math.random() * 3000));
}
}
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/form/radio.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ THE SOFTWARE.
toggles the radio.
</st:attribute>
</st:documentation>
<j:set var="itemId" value="${h.generateItemId(id)}" />
<j:set var="itemId" value="${attrs.id ?: h.generateItemId()}" />
<div class="jenkins-radio">
<input class="jenkins-radio__input" type="radio" name="${attrs.name}" onclick="${attrs.onclick}"
id="${itemId}" value="${attrs.value}" checked="${attrs.checked?'true':null}"
Expand Down

0 comments on commit f25a406

Please sign in to comment.