Share your thoughts in the 2025 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in Syntax and reader by

Strings suppose to support standard Java escape sequences, including octal escape sequence: [0-7]{1,3}

In Java decoding of octal sequences stop at the first non-octal digit or any other character if there are 1 or two octal digits in the escape sequence. For example:

jshell> "\18"
$1 ==> "\0018"

But Clojure reads up to 3 potentially octal digits greedily resulting in wrongly consuming non-octal digits:

Clojure 1.12.4
user=> "\18"
Syntax error reading source at (REPL:1:5).
Invalid digit: 8

non-octal characters:

Clojure 1.12.4
user=> "\1d"
Syntax error reading source at (REPL:1:5).
Invalid digit: d

And succeed only when there is line terminator or exact three octal digits in supported octal range:

Clojure 1.12.4
user=> "\1"
""
user=> "\1"
""
user=> "\12"
"\n"
user=> "\123"
"S"
user=> "\123d"
"Sd"

Please log in or register to answer this question.

...