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.
@@ -34,6 +34,8 @@ def restore_default_behavior | |||
# @return [Integer] The number of lines loaded | |||
def load | |||
@loader.call do |line| | |||
next if invalid_readline_line?(line) |
kyrylo
Oct 10, 2018
Member
I wonder if we should substitute \0
with a blank instead? Like you said in #1789 you typed that by accident, right?
I wonder if we should substitute \0
with a blank instead? Like you said in #1789 you typed that by accident, right?
owst
Oct 10, 2018
Author
Contributor
When you say "substitute \0
with a blank" do you mean "we could delete \0
s" 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-space
is one keypress sequence to type a literal NULL byte, for me on Linux, the sequence ctrl-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
When you say "substitute \0
with a blank" do you mean "we could delete \0
s" 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-space
is 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
kyrylo
Oct 10, 2018
Member
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.
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.
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.
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.