tools.reader

In strings, octal escapes above 0337 are considered invalid.

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

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:

"à"

Activity

Hide
Nicola Mometto added a comment -

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

Show
Nicola Mometto added a comment - Thanks, this needs to be fixed for edn and the cljs version too, could you update the patch?
Hide
Alex ter Weele added a comment - - edited

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!

Show
Alex ter Weele added a comment - - edited 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!
Hide
Nicola Mometto added a comment - - edited

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

Show
Nicola Mometto added a comment - - edited Alex ter Weele can you please sign the CA? See https://clojure.org/community/contributing I can't take your patch until you do
Hide
Alex ter Weele added a comment -

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

Show
Alex ter Weele added a comment - Thank you for pointing that out; I have now done so.
Hide
Nicola Mometto added a comment -

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

Show
Nicola Mometto added a comment - 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

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: