Skip to content

Commit 53aa0af

Browse files
bcordisclaude
andcommitted
fix: loop tag stripping and remove entity decoding for CodeQL
Use loop-until-stable regex stripping (same pattern as transcript fix) to handle malformed nested tags. Remove entity decoding that caused double-unescape finding — introPreview goes through escHtml() on output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5ac6da3 commit 53aa0af

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

build/media_source/js/message-wizard.es6.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ document.addEventListener('DOMContentLoaded', () => {
181181
introText = getValue('jform_studyintro');
182182
}
183183

184-
// Strip HTML tags for preview using regex (no DOM parsing needed)
185-
let introPreview = introText.replace(/<[^>]*>/g, '');
186-
// Decode common HTML entities
187-
introPreview = introPreview.replace(/&amp;/g, '&').replace(/&lt;/g, '<')
188-
.replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#039;/g, "'")
189-
.replace(/&nbsp;/g, ' ');
190-
introPreview = introPreview.substring(0, 200);
184+
// Strip HTML tags for plain-text preview.
185+
// Loop until stable to handle malformed/nested tags.
186+
// Then use the escHtml helper below when inserting into the preview.
187+
let introStripped = introText;
188+
let prevIntro;
189+
do {
190+
prevIntro = introStripped;
191+
introStripped = introStripped.replace(/<[^>]*>/g, '');
192+
} while (introStripped !== prevIntro);
193+
const introPreview = introStripped.substring(0, 200);
191194

192195
const escHtml = (str) => {
193196
const d = document.createElement('div');

0 commit comments

Comments
 (0)