REPL hangs after reading an unsupported escape character


Steps to reproduce:
1. Start a repl with `clj`.
2. Type `"\."` into the REPL. Hit enter.

Expected result: The REPL returns an error and a prompt.

Actual result: The REPL returns an error and waits for the user to terminate the string.

I'm not sure this is a bug, but I ran into it while documenting a regexp and it wasn't obvious what was happening or how to resolve it. Also, if you send `"\." "(print 'hit)"`, it will execute the print expression, which could be dangerous.

Exception tracee:




Alex Miller
July 31, 2020, 3:42 AM

What's happening is the read throws at the bad character but does not consume until the end of the line (or whatever - this is a tricky case) so at the next prompt the unconsumed input is read (the opening quote).

The tricky part is that you don't actually know where the "end" of the intended input is. This could be a multi-line copy/paste or there literally could be multiple expressions in the first line. And clojure.main also supports reading from stdin (arbitrary input stream) etc. Seems obvious at first, but in reality is quite tricky.

The common case where you see something like this is when a read error occurs between any delimited pair, often a list or vector:

In these cases, as the exception propagates back up the stack, I wonder if it would be possible to also continue to try to read and discard until the matching delimiter. Maybe an idea worth thinking about, but doesn't seem urgent.




Austin Haas






Affects versions