Repository navigation
Gracefully handle (ignore) null bytes in history lines - #1790
Conversation
Fixes #1789. Readline is unable to add lines to its history that contain a null byte; we should therefore avoid saving such lines to the history file, and ignore any such lines that are already present in the file.
| # @return [Integer] The number of lines loaded | ||
| def load | ||
| @loader.call do |line| | ||
| next if invalid_readline_line?(line) |
There was a problem hiding this comment.
I wonder if we should substitute \0 with a blank instead? Like you said in #1789 you typed that by accident, right?
There was a problem hiding this comment.
When you say "substitute \0 with a blank" do you mean "we could delete \0s" or do you mean "we could replace each \0 with a (a space)"? I think you might mean the latter, since in #1789 I said I typed ctrl-space instead of space to generate \0.
I see some issues:
- In general a null byte bears no relation to a space -
ctrl-spaceis one keypress sequence to type a literal NULL byte, for me on Linux, the sequencectrl-v, ctrl-shift-'also enters a NULL byte, and there's likely other ways too - There's no guarantee that the NULL byte appears in a position where adding a space is syntactically valid (e.g.
x\0y = 1) - The simple symmetry between "don't save invalid lines" and "don't load existing invalid lines" would be broken
What do you think? I think the behaviour as-is in this PR is simple and likely to be most-often correct vs attempting to modify invalid lines
There was a problem hiding this comment.
I think you might mean the latter [...]
That's correct. This is what I meant.
Thanks for the analysis, I agree with this decision. I was just wondering about the "what-if" but your points sound very convincing.
Fixes #1789.
Readline is unable to add lines to its history that contain a null byte;
we should therefore avoid saving such lines to the history file, and
ignore any such lines that are already present in the file.