Skip to content

Commit

Permalink
Fix unescaping strings for racket, elixir and io
Browse files Browse the repository at this point in the history
  • Loading branch information
iqbalansari authored and kanaka committed Sep 28, 2017
1 parent 0794206 commit 1b17329
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
6 changes: 2 additions & 4 deletions elixir/lib/mal/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ defmodule Mal.Reader do
cond do
String.starts_with?(token, "\"") and String.ends_with?(token, "\"") ->
token
|> String.slice(1..-2)
|> String.replace("\\\"", "\"")
|> String.replace("\\n", "\n")
|> String.replace("\\\\", "\\")
|> Code.string_to_quoted
|> elem(1)

integer?(token) ->
Integer.parse(token)
Expand Down
3 changes: 2 additions & 1 deletion io/MalReader.io
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ MalReader := Object clone do (
numberRegex := Regex with("^-?[0-9]+$")

read_string := method(token,
token exSlice(1, -1) replaceSeq("\\\"", "\"") replaceSeq("\\n", "\n") replaceSeq("\\\\", "\\")
placeholder := 127 asCharacter
token exSlice(1, -1) replaceSeq("\\\\", placeholder) replaceSeq("\\\"", "\"") replaceSeq("\\n", "\n") replaceSeq(placeholder, "\\")
)

read_atom := method(rdr,
Expand Down
8 changes: 1 addition & 7 deletions racket/reader.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@
[(regexp-match #px"^-?[0-9][0-9.]*$" token)
(string->number token)]
[(regexp-match #px"^\".*\"$" token)
(string-replace
(string-replace
(string-replace
(substring token 1 (- (string-length token) 1))
"\\\"" "\"")
"\\n" "\n")
"\\\\" "\\")]
(with-input-from-string token read)]
[(regexp-match #px"^:" token) (_keyword (substring token 1))]
[(equal? "nil" token) nil]
[(equal? "true" token) #t]
Expand Down

0 comments on commit 1b17329

Please sign in to comment.