In strings, octal escapes above 0337 are considered invalid.

Description

Example:

(clojure.tools.reader/read-string "\"\\340\"")

Throws an exception:

ExceptionInfo Octal escape sequence must be in range [0, 377]. clojure.core/ex-info (core.clj:4725)

The octal number 0340 is less than the octal number 0377. The expected result is:

"à"

Environment

None

Activity

Show:
Nicola Mometto
October 16, 2017, 3:30 PM

Thanks, this needs to be fixed for edn and the cljs version too, could you update the patch?

Alex ter Weele
October 17, 2017, 2:32 AM

Here is an updated patch. I have moved tests to common_tests.clj so that they cover both clojure.tools.reader and clojure.tools.reader.edn. I added tests for cljs. I changed the constant 0337 to 0377 where applicable.

To my surprise, the tests that I added for cljs do not fail on the old code or the new code. I believe this is because (int \à) evaluates to 0 in cljs. See cljs.tools.reader/escape-char. This could be user error on my part--I have not done any Clojurescript before this and I had to do some unfamiliar environment setup.

If my thinking here is correct, then (cljs.tools.reader/read-string "\"\\400\"") and (cljs.tools.reader.edn/read-string "\"\\400\"") will evaluate to "Ā" when an error is expected. Can you confirm?

Thank you for your time on this!

Nicola Mometto
November 2, 2017, 2:24 PM

can you please sign the CA? See https://clojure.org/community/contributing I can't take your patch until you do

Alex ter Weele
November 7, 2017, 12:58 AM

Thank you for pointing that out; I have now done so.

Nicola Mometto
November 7, 2017, 5:18 PM

Merged, thanks.
I'll take a look at the cljs case separately as lack of validation is not as serious as not accepting valid code

Completed

Assignee

Nicola Mometto

Reporter

Alex ter Weele

Labels

None

Approval

None

Patch

Code and Test

Priority

Minor