Skip to content
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

Sanitize text pasted into hex text boxes #3684

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

kalimag
Copy link
Contributor

@kalimag kalimag commented Jun 17, 2023

  • Add ClipboardEventTextBox control with an OnPaste method and make HexTextBox and WatchValueBox inherit from that

  • Override normal paste behavior to trim 0x/$/whitespace from pasted text

  • Prevent pasting of non-hex text

Resolves #3682

@adelikat
Copy link
Contributor

adelikat commented May 7, 2024

Does this specifically break any functionality on unix? or just fail to add new functionality? If it is the former, I say we merge this

Copy link
Member

@YoshiRulz YoshiRulz left a comment

Choose a reason for hiding this comment

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

adelikat is right, this is better than what we have. Please rebase.

src/BizHawk.Client.EmuHawk/CustomControls/HexTextBox.cs Outdated Show resolved Hide resolved
@@ -435,6 +437,21 @@ protected override void OnTextChanged(EventArgs e)
base.OnTextChanged(e);
}

protected override void OnPaste(PasteEventArgs e)
Copy link
Member

@YoshiRulz YoshiRulz May 7, 2024

Choose a reason for hiding this comment

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

(ditto of everything that applies to other impl.)

int availableLength = MaxLength - TextLength + SelectionLength;
if (text.Length > availableLength)
{
text = text.Substring(0, availableLength);
Copy link
Member

Choose a reason for hiding this comment

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

Style nitpicks: Add argument names here, use var everywhere, use is for enum/const comparison, use string.Empty, and make PasteEventArgs sealed.

Trim `0x` and `$` prefixes and whitespace pasted into `HexTextBox` and `WatchValueBox`. Prevent pasting non-hex text.

Add `ClipboardEventTextBox` control with `OnPaste` event
@kalimag
Copy link
Contributor Author

kalimag commented May 14, 2024

HexEditor currently uses NumericStringExtensions.OnlyHex for its own custom paste handling. This could be unified with the new NumericStringExtensions.CleanHex, but it's more broad (e.g. "0xwhat_ever".OnlyHex() == "0AEE").

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.

[F.Rq.] Allow pasting 0xHHHH-formatted numbers in a HexTextBox (e.g. in WatchEditor)
3 participants