1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | =head1 NAME |
3 | =head1 NAME |
4 | |
4 | |
5 | confirm-paste - ask for confirmation before pasting multiline text |
5 | confirm-paste - ask for confirmation before pasting cntrol characters |
6 | |
6 | |
7 | =head1 DESCRIPTION |
7 | =head1 DESCRIPTION |
8 | |
8 | |
9 | Displays a confirmation dialog when a paste containing at least a full |
9 | Displays a confirmation dialog when a paste containing control characters |
10 | line is detected. |
10 | is detected. |
|
|
11 | |
|
|
12 | This is mostly meant as a defense-in-depth mechanism to protect against |
|
|
13 | the common webbrowser bug of you selecting some text but the browser |
|
|
14 | pasting a completely different text, which has some attack potential. |
|
|
15 | |
|
|
16 | It can also be useful to prevent you from accidentally pasting large |
|
|
17 | amounts of text. |
11 | |
18 | |
12 | =cut |
19 | =cut |
13 | |
20 | |
14 | sub msg { |
21 | sub msg { |
15 | my ($self, $msg) = @_; |
22 | my ($self, $msg) = @_; |
… | |
… | |
19 | } |
26 | } |
20 | |
27 | |
21 | sub on_tt_paste { |
28 | sub on_tt_paste { |
22 | my ($self, $str) = @_; |
29 | my ($self, $str) = @_; |
23 | |
30 | |
24 | my $count = ($str =~ tr/\012\015//); |
31 | my $count = ($str =~ tr/[\x00-\x1f\x80-\x9f]//) |
25 | |
32 | or return; |
26 | return unless $count; |
|
|
27 | |
33 | |
28 | $self->{paste} = \$str; |
34 | $self->{paste} = \$str; |
29 | $self->msg ("Paste of $count lines, continue? (y/n)"); |
35 | $self->msg ("Pasting $count control characters, continue? (y/n)"); |
|
|
36 | |
30 | my $preview = substr $self->locale_decode ($str), 0, $self->ncol; |
37 | my $preview = substr $self->locale_decode ($str), 0, $self->ncol; |
31 | $preview =~ s/\n/\\n/g; |
38 | $preview =~ s/\n/\\n/g; |
|
|
39 | $preview =~ s/([\x00-\x1f\x80-\x9f])/sprintf "\\x%02x", ord $1/ge; |
|
|
40 | |
32 | $self->{overlay}->set (0, 1, $self->special_encode ($preview)); |
41 | $self->{overlay}->set (0, 1, $self->special_encode ($preview)); |
33 | $self->enable (key_press => \&key_press); |
42 | $self->enable (key_press => \&key_press); |
34 | |
43 | |
35 | 1 |
44 | 1 |
36 | } |
45 | } |