Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 3; |
21 |
use Template; |
22 |
|
23 |
my $template = Template->new({ |
24 |
PLUGIN_BASE => 'Koha::Template::Plugin', |
25 |
}); |
26 |
|
27 |
my $tt = <<EOF; |
28 |
[%- USE raw %] |
29 |
[%- USE Filter %] |
30 |
[%~ uri_url_filtered = BLOCK %][% uri | url ~%][% END -%] |
31 |
[%- Filter.no_double_encode( uri_url_filtered ) | \$raw -%] |
32 |
EOF |
33 |
|
34 |
my $uri = 'https://www.foo.com/url?q=https://bar.org'; |
35 |
my $encoded_uri = 'https://www.foo.com/url?q=https%3A%2F%2Fbar.org'; |
36 |
my $output = ''; |
37 |
my $vars = { uri => $uri }; |
38 |
$template->process(\$tt, $vars, \$output); |
39 |
is($output, $uri); |
40 |
|
41 |
$output = ''; |
42 |
$vars = { uri => $encoded_uri }; |
43 |
$template->process(\$tt, $vars, \$output); |
44 |
# uri filter would have generated https://www.foo.com/url?q=https%253A%252F%252Fbar.org |
45 |
is($output, $encoded_uri, 'URI is not double encoded'); |