Skip to content

Commit 69cd2b5

Browse files
authored
Merge pull request #214 from rnva/fix/remove-inline-onclick-handlers
Replace inline onclick handlers with JS-attached listeners
2 parents 0c52bc1 + e4bccf5 commit 69cd2b5

7 files changed

Lines changed: 76 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1212

1313
### Internal
1414

15+
- Replaced the inline `onclick` attributes on the sequence group/note/box modal submit buttons (`sequence_menus.html`) and the version badge (`index.html`) with JavaScript-attached listeners wired in their existing once-run setup (`groupOperationEventListeners`/`noteOperationEventListeners`/`boxEventListeners`/`buttonEventListeners`), matching how the message and participant submit buttons were already bound. No behavior change in the browser; inline event handlers are refused under a strict Content-Security-Policy (e.g. a webview), where these buttons silently did nothing. Added `tests/e2e/test_sequence_submit_buttons.py`.
1516
- Rewrote `Diagram._assign_participant_indexes` (`sequence/classes.py`) to map each participant to its declaration line by displayed name (quoted or bare, via the new `PARTICIPANT_DECLARATION_RE`/`_declared_participant_name`) rather than by position. Implicitly-introduced participants correctly keep index `-1` ("no declaration line") instead of shifting every later participant onto the wrong line, and `add_box` now rejects a negative index rather than letting Python's negative indexing invert the box. Added `tests/sequence/test_participant_indexes.py` and implicit-participant cases in `tests/sequence/test_box.py`.
1617
- Removed leftover module-level debug prints from `shared/puml_encoder.py`.
1718

src/plantuml_gui/static/script.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ rnote over Alice, Bob: An "R Note" can span participants
253253

254254
function buttonEventListeners() {
255255

256+
document.getElementById('version').addEventListener('click', toggleVersionPanel);
257+
256258
document.getElementById('demo').addEventListener('click', function() {
257259
setDemo()
258260
});

src/plantuml_gui/static/sequence-box.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ async function submitBox(startIndex, endIndex) {
221221
// --- Event listener registration ---
222222

223223
function boxEventListeners() {
224+
// Submit button in the box edit modal
225+
$('#seq-submit-box').on('click', submitBoxEdit);
226+
224227
// "Box" item in the participant context menu enters box-add mode.
225228
document.getElementById('seq-addBox').addEventListener('click', (e) => {
226229
e.preventDefault();

src/plantuml_gui/static/sequence-operations.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,9 @@ function cssColorValue(color) {
867867
}
868868

869869
function noteOperationEventListeners() {
870+
// Submit button in the note modal (Add / Edit)
871+
$('#seq-submit-note').on('click', submitNote);
872+
870873
// "Add Note" in sequence-menu shows the note type submenu
871874
document.getElementById('seq-addNote').addEventListener('click', function(e) {
872875
e.preventDefault();
@@ -1004,6 +1007,9 @@ function noteOperationEventListeners() {
10041007
let groupEditMode = false;
10051008

10061009
function groupOperationEventListeners() {
1010+
// Submit button in the group label modal (Add / Rename)
1011+
$('#seq-submit-group').on('click', submitGroup);
1012+
10071013
// "Rename" context menu item: fetch current label and show the group modal
10081014
document.getElementById('seq-renameGroup').addEventListener('click', async function() {
10091015
var element = document.getElementById('colb');

src/plantuml_gui/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<span class="toolbar-sep"></span>
9797
<span class="toolbar-spacer"></span>
9898
<div class="dropdown-wrapper" style="position:relative">
99-
<span class="version-badge" id="version" onclick="toggleVersionPanel()" data-tippy-content="Version History">v{{version}}</span>
99+
<span class="version-badge" id="version" data-tippy-content="Version History">v{{version}}</span>
100100
<div class="dropdown-panel version-panel" id="version-panel"></div>
101101
</div>
102102
<button type="button" class="toolbar-btn" data-toggle="modal" data-target="#usageModal" data-tippy-content="Help">

src/plantuml_gui/templates/partials/sequence_menus.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ <h5 class="modal-title">Add Note</h5>
166166
</div>
167167
</div>
168168
<div class="modal-footer">
169-
<button id="seq-submit-note" type="button" class="btn btn-primary" onclick="submitNote()">Submit</button>
169+
<button id="seq-submit-note" type="button" class="btn btn-primary">Submit</button>
170170
</div>
171171
</div>
172172
</div>
@@ -203,7 +203,7 @@ <h5 class="modal-title">Add Group</h5>
203203
</div>
204204
</div>
205205
<div class="modal-footer">
206-
<button id="seq-submit-group" type="button" class="btn btn-primary" onclick="submitGroup()">Submit</button>
206+
<button id="seq-submit-group" type="button" class="btn btn-primary">Submit</button>
207207
</div>
208208
</div>
209209
</div>
@@ -230,7 +230,7 @@ <h5 class="modal-title">Edit Box</h5>
230230
</div>
231231
</div>
232232
<div class="modal-footer">
233-
<button id="seq-submit-box" type="button" class="btn btn-primary" onclick="submitBoxEdit()">Submit</button>
233+
<button id="seq-submit-box" type="button" class="btn btn-primary">Submit</button>
234234
</div>
235235
</div>
236236
</div>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2026 Ericsson
6+
7+
"""Regression probes for the sequence modal submit buttons.
8+
9+
The group/note/box submit buttons used to carry inline ``onclick`` attributes.
10+
A browser runs those, but a strict Content-Security-Policy (the VS Code webview
11+
the frontend is reused in) refuses inline event handlers, so the buttons did
12+
nothing there. They are now wired with JavaScript-attached listeners, like the
13+
message/participant submit buttons already were. These tests lock that in:
14+
no inline handler survives, and a click actually reaches the backend.
15+
"""
16+
17+
18+
class TestSequenceSubmitButtons:
19+
def test_submit_buttons_have_no_inline_onclick(self, app_url, page):
20+
result = page.evaluate(
21+
"""() => ({
22+
group: document.getElementById('seq-submit-group').getAttribute('onclick'),
23+
note: document.getElementById('seq-submit-note').getAttribute('onclick'),
24+
box: document.getElementById('seq-submit-box').getAttribute('onclick'),
25+
})"""
26+
)
27+
assert result == {"group": None, "note": None, "box": None}
28+
29+
def test_clicking_group_submit_reaches_the_backend(self, app_url, page):
30+
# Wire the listeners (as sequenceEventListeners does on a real render),
31+
# stub fetch to capture the call, then click the button natively.
32+
called = page.evaluate(
33+
"""async () => {
34+
groupOperationEventListeners();
35+
document.getElementById('colb').innerHTML =
36+
'<svg viewBox="0 0 300 200"><g></g></svg>';
37+
38+
const calls = [];
39+
const realFetch = window.fetch;
40+
window.fetch = (url, opts) => {
41+
calls.push(String(url));
42+
return Promise.resolve({
43+
json: () => Promise.resolve({ plantuml: editor.session.getValue() })
44+
});
45+
};
46+
47+
groupEditMode = false;
48+
selectedGroupType = 'group';
49+
const submit = document.getElementById('seq-submit-group');
50+
submit.dataset.startIndex = '2';
51+
submit.dataset.endIndex = '3';
52+
53+
submit.dispatchEvent(new MouseEvent('click', { bubbles: true }));
54+
await new Promise((r) => setTimeout(r, 50));
55+
56+
window.fetch = realFetch;
57+
return calls;
58+
}"""
59+
)
60+
assert any("addGroup" in url for url in called)

0 commit comments

Comments
 (0)