Remove inline event handlers in the soy template. This is required to be able to use strict-dynamic CSP. The script tags will be updated with nonce by the Soy library. Google-Bug-Id: b/216788721 Release-Notes: skip Change-Id: I2db1e423b8186bae835128307ecc97fa01beed1a
diff --git a/resources/com/google/gitiles/templates/ObjectDetail.soy b/resources/com/google/gitiles/templates/ObjectDetail.soy index 3d3c6e4..054f621 100644 --- a/resources/com/google/gitiles/templates/ObjectDetail.soy +++ b/resources/com/google/gitiles/templates/ObjectDetail.soy
@@ -270,7 +270,7 @@ {let $n: $index + 1 /} <tr class="u-pre u-monospace FileContents-line"> <td class="u-lineNum u-noSelect FileContents-lineNum" - data-line-number="{$n}" onclick="window.location.hash='#{$n}'"></td> + data-line-number="{$n}"></td> <td class="FileContents-lineContents" id="{$n}"> {for $span in $line} <span class="{$span.classes}">{$span.text}</span> @@ -279,6 +279,14 @@ </tr> {/for} </table> + <script> + for (let lineNumEl of document.querySelectorAll('td.u-lineNum')) {lb} + lineNumEl.onclick = () => {lb} + window.location.hash = + `#${lb}lineNumEl.getAttribute('data-line-number'){rb}`; + {rb}; + {rb} + </script> {else} <div class="FileContents-empty">Empty file</div> {/if}
diff --git a/resources/com/google/gitiles/templates/RepositoryIndex.soy b/resources/com/google/gitiles/templates/RepositoryIndex.soy index ac1ab56..e8ec346 100644 --- a/resources/com/google/gitiles/templates/RepositoryIndex.soy +++ b/resources/com/google/gitiles/templates/RepositoryIndex.soy
@@ -67,8 +67,7 @@ <div class="CloneRepo"> <div class="CloneRepo-title">Clone this repo:</div> - <input type="text" class="u-monospace CloneRepo-command" - onclick="this.focus();if(this.selectionStart==this.selectionEnd){lb}this.select(){rb}" + <input id="clone-repo-input" type="text" class="u-monospace CloneRepo-command" readonly="readonly" value="git clone {$cloneUrl}"> </div> @@ -99,6 +98,19 @@ {call common.footer} {param customVariant: $customVariant /} {/call} + +<script> + {lb} + let f = document.getElementById("clone-repo-input"); + f.onclick = () => {lb} + f.focus(); + if (f.selectionStart === f.selectionEnd) {lb} + f.select(); + {rb} + {rb}; + {rb} +</script> + {/template} /**