-
Notifications
You must be signed in to change notification settings - Fork 55
Add options/0 #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add options/0 #87
Conversation
| MyApp.CSV, | ||
| NimbleCSV.RFC4180.options() | ||
| |> Keyword.merge( | ||
| escape_formula: %{~w(@ + - = \\t \\r) => "'"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 `'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) => "'"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed for consistency.
|
💚 💙 💜 💛 ❤️ |
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).