mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
disallow paste of non hex characters
This commit is contained in:
parent
55dcf4c65f
commit
a0c3083af0
1 changed files with 18 additions and 2 deletions
|
@ -22,6 +22,8 @@ namespace WinUI
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
APIHandler handler = new APIHandler();
|
APIHandler handler = new APIHandler();
|
||||||
|
Regex charRegex = new Regex("[0-9a-fxA-FX]");
|
||||||
|
Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
@ -29,6 +31,8 @@ namespace WinUI
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
updateNetworks();
|
updateNetworks();
|
||||||
|
|
||||||
|
DataObject.AddPastingHandler(joinNetworkID, OnPaste);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStatus()
|
private void updateStatus()
|
||||||
|
@ -61,8 +65,20 @@ namespace WinUI
|
||||||
|
|
||||||
private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
|
private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
|
||||||
{
|
{
|
||||||
Regex regex = new Regex("[0-9a-fxA-FX]");
|
e.Handled = !charRegex.IsMatch(e.Text);
|
||||||
e.Handled = !regex.IsMatch(e.Text);
|
}
|
||||||
|
|
||||||
|
private void OnPaste(object sender, DataObjectPastingEventArgs e)
|
||||||
|
{
|
||||||
|
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
|
||||||
|
if (!isText) return;
|
||||||
|
|
||||||
|
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
|
||||||
|
|
||||||
|
if (!wholeStringRegex.IsMatch(text))
|
||||||
|
{
|
||||||
|
e.CancelCommand();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue