Conversation
rhcarvalho
commented
Jun 28, 2025
| MyApp.CSV, | ||
| NimbleCSV.RFC4180.options() | ||
| |> Keyword.merge( | ||
| escape_formula: %{~w(@ + - = \\t \\r) => "'"}, |
Contributor
Author
There was a problem hiding this comment.
For some reason ExDoc needed the \\t and \\r escaping, otherwise it would produce a broken code snippet by interpreting the tab and carriage return.
| ) | ||
|
|
||
| """ | ||
| @callback options() :: keyword() |
Contributor
Author
There was a problem hiding this comment.
Made it a callback to match the other parts of the API.
| * `:escape_formula` - an optional map of formula prefixes to escape sequences. | ||
| When `nil` (the default), formula escaping is disabled. For example, | ||
| `%{~w(@ + - = \t \r) => "'"}` escapes fields starting with `@`, `+`, `-`, `=`, | ||
| tab, or carriage return by prefixing them with `'` |
Contributor
Author
There was a problem hiding this comment.
Reworded this to improve flow. Similar to :trim_bom, :escape_formula requires more explanation so ends up being multiple sentences. Still, like all options, it doesn't end with punctuation.
| follow the [OWASP recommendations](https://owasp.org/www-community/attacks/CSV_Injection): | ||
|
|
||
| escape_formula: %{["@", "+", "-", "=", "\t", "\r"] => "'"} | ||
| escape_formula: %{~w(@ + - = \t \r) => "'"} |
Contributor
Author
There was a problem hiding this comment.
Changed for consistency.
Member
|
💚 💙 💜 💛 ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #86 (comment) / #86 (comment), to make it easier to customize the existing CSV modules, in particular to add formula escaping (on user code).