Skip to content

Commit f17310a

Browse files
committed
Fixed issue #9, I think
1 parent bcbfde0 commit f17310a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

slashes.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ function slash(prog) {
3333
if (state == 1 && print!="") { logPrint(); res += print; print = ""; }
3434
if (state == 3) {
3535
var isVerbose = false;
36+
var iters = 0; const MAX_ITERS = 1280;
3637
while (prog.includes(pattern)) {
37-
prog = prog? prog.replace(pattern, replacement) : prog;
38-
// Just `prog = prog.replace(pat, rep);` might be good enough
39-
// Was trying to get rid of the null character that was printing
40-
// Thought maybe the replacement with an empty string pattern was undefined
41-
if (isVerbose) { logApply(); }
38+
if (iters > MAX_ITERS) { print+='...'; break; }
39+
iters++;
40+
prog = prog? prog.replace(pattern, replacement) : prog;
41+
// Just `prog = prog.replace(pat, rep);` might be good enough
42+
// Was trying to get rid of the null character that was printing
43+
// Thought maybe the replacement with an empty string pattern was undefined
44+
if (isVerbose) { logApply(); }
4245
}
4346
if (!isVerbose) { logApply(); }
4447
pattern = ""; replacement = "";

0 commit comments

Comments
 (0)