Skip to content

Gracefully handle (ignore) null bytes in history lines #1790

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

Merged
merged 1 commit into from
Oct 12, 2018
Merged

Gracefully handle (ignore) null bytes in history lines #1790

merged 1 commit into from
Oct 12, 2018

Conversation

owst
Copy link
Contributor

@owst owst commented Oct 9, 2018

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.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should substitute \0 with a blank instead? Like you said in #1789 you typed that by accident, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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
  2. There's no guarantee that the NULL byte appears in a position where adding a space is syntactically valid (e.g. x\0y = 1)
  3. 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kyrylo kyrylo merged commit 888e5e3 into pry:master Oct 12, 2018
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