Skip to content

Fix :escape_formula examples that ignore tabs and CRs - #95

Merged
josevalim merged 1 commit into
dashbitco:masterfrom
kidq330:kidq330/fix_wordlist
Sep 19, 2026
Merged

josevalim merged 1 commit into
dashbitco:masterfrom
kidq330:kidq330/fix_wordlist

Conversation

@kidq330

@kidq330 kidq330 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Docs and tests use escape_sequence: ~w(@ + - = \r \t) which actually omits \r and \t:

escapes = ~w(@ + - = \t \r)

NimbleCSV.define(
  Parser1,
  NimbleCSV.RFC4180.options()
  |> Keyword.merge(escape_formula: %{escapes => "'"})
)

[["\t=1+1"]] |> Parser1.dump_to_iodata() |> IO.iodata_to_binary()

NimbleCSV.define(
  Parser2,
  NimbleCSV.RFC4180.options()
  |> Keyword.merge(escape_formula: %{["@", "+", "-", "=", "\r", "\t"] => "'"})
)

[["\t=1+1"]] |> Parser2.dump_to_iodata() |> IO.iodata_to_binary()
iex(1)> escapes = ~w(@ + - = \t \r)
["@", "+", "-", "="]
iex(2)> NimbleCSV.define(
...(2)>   Parser1,
...(2)>   NimbleCSV.RFC4180.options()
...(2)>   |> Keyword.merge(escape_formula: %{escapes => "'"})
...(2)> )
{:module, Parser1,
 <<70, 79, 82, 49, 0, 0, 67, 252, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 3, 209,
   0, 0, 0, 84, 14, 69, 108, 105, 120, 105, 114, 46, 80, 97, 114, 115, 101, 114,
   49, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, :ok}
iex(3)> [["\t=1+1"]] |> Parser1.dump_to_iodata() |> IO.iodata_to_binary()
"\t=1+1\r\n"
iex(4)> NimbleCSV.define(
...(4)>   Parser2,
...(4)>   NimbleCSV.RFC4180.options()
...(4)>   |> Keyword.merge(escape_formula: %{["@", "+", "-", "=", "\r", "\t"] => "'"})
...(4)> )
{:module, Parser2,
 <<70, 79, 82, 49, 0, 0, 68, 60, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 3, 209,
   0, 0, 0, 84, 14, 69, 108, 105, 120, 105, 114, 46, 80, 97, 114, 115, 101, 114,
   50, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, :ok}
iex(5)> [["\t=1+1"]] |> Parser2.dump_to_iodata() |> IO.iodata_to_binary()
"'\t=1+1\r\n"

@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@josevalim
josevalim merged commit edd9687 into dashbitco:master Sep 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants