diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b33e7171ef42a7282f0e572c28ffe1511977958..e0284787d48cb8b1db3f8411612c3d72752f9c93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ This file contains the changes applied to the sources of converse<br>
 The current build version of converse is: `v7.0.3dev`<br>
 If the converse sources have to be updated, apply these changes again, or fix them using plugins
 
+### 2021-04-15
+* Fix an endless loop when parsing bad formatted code block messages
+
 ### 2021-03-12
 * Added the `fa-reply` icon into the icons svg (icons.js)
 
diff --git a/src/conversejs/converse.js b/src/conversejs/converse.js
index 3c5384270fbb527134030b33d6416d0c3d58cf69..30105fea11eb49a5bfd148b010c855a51f55880e 100644
--- a/src/conversejs/converse.js
+++ b/src/conversejs/converse.js
@@ -91770,7 +91770,7 @@ function getDirectiveLength(d, text, i) {
     return 0;
   } else {
     const substring = text.slice(i + 1);
-    let j;
+    let j = 0;
     let idx = substring.indexOf(d);
 
     while (idx !== -1) {