Filename | /var/www/foswikidev/core/lib/Foswiki/Macros/URLPARAM.pm |
Statements | Executed 69 statements in 581µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 1 | 1 | 46µs | 120µs | URLPARAM | Foswiki::
1 | 1 | 1 | 14µs | 28µs | BEGIN@4.68 | Foswiki::
3 | 1 | 1 | 11µs | 11µs | _handleURLPARAMValue | Foswiki::
1 | 1 | 1 | 10µs | 14µs | BEGIN@5.69 | Foswiki::
1 | 1 | 1 | 4µs | 4µs | BEGIN@7.70 | Foswiki::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki; | ||||
3 | |||||
4 | 2 | 28µs | 2 | 41µs | # spent 28µs (14+14) within Foswiki::BEGIN@4.68 which was called:
# once (14µs+14µs) by Foswiki::_expandMacroOnTopicRendering at line 4 # spent 28µs making 1 call to Foswiki::BEGIN@4.68
# spent 14µs making 1 call to strict::import |
5 | 2 | 50µs | 2 | 18µs | # spent 14µs (10+4) within Foswiki::BEGIN@5.69 which was called:
# once (10µs+4µs) by Foswiki::_expandMacroOnTopicRendering at line 5 # spent 14µs making 1 call to Foswiki::BEGIN@5.69
# spent 4µs making 1 call to warnings::import |
6 | |||||
7 | # spent 4µs within Foswiki::BEGIN@7.70 which was called:
# once (4µs+0s) by Foswiki::_expandMacroOnTopicRendering at line 12 | ||||
8 | 1 | 5µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
9 | require locale; | ||||
10 | import locale(); | ||||
11 | } | ||||
12 | 1 | 447µs | 1 | 4µs | } # spent 4µs making 1 call to Foswiki::BEGIN@7.70 |
13 | |||||
14 | # spent 120µs (46+74) within Foswiki::URLPARAM which was called 3 times, avg 40µs/call:
# 3 times (46µs+74µs) by Foswiki::_expandMacroOnTopicRendering at line 3435 of /var/www/foswikidev/core/lib/Foswiki.pm, avg 40µs/call | ||||
15 | 3 | 2µs | my ( $this, $params ) = @_; | ||
16 | 3 | 1µs | my $param = $params->{_DEFAULT} || ''; | ||
17 | 3 | 1µs | my $newLine = $params->{newline}; | ||
18 | 3 | 1µs | my $encode = $params->{encode} || 'safe'; | ||
19 | 3 | 800ns | my $multiple = $params->{multiple}; | ||
20 | 3 | 600ns | my $separator = $params->{separator}; | ||
21 | 3 | 700ns | my $default = $params->{default}; | ||
22 | |||||
23 | 3 | 800ns | $separator = "\n" unless ( defined $separator ); | ||
24 | |||||
25 | 3 | 600ns | my $value = ''; | ||
26 | 3 | 2µs | if ( $this->{request} ) { | ||
27 | 3 | 5µs | 3 | 7µs | if ( Foswiki::isTrue($multiple) ) { # spent 7µs making 3 calls to Foswiki::isTrue, avg 2µs/call |
28 | my @valueArray = $this->{request}->multi_param($param); | ||||
29 | if (@valueArray) { | ||||
30 | |||||
31 | # join multiple values properly | ||||
32 | unless ( $multiple =~ m/^on$/i ) { | ||||
33 | my $item = ''; | ||||
34 | @valueArray = map { | ||||
35 | $item = $_; | ||||
36 | $_ = $multiple; | ||||
37 | $_ .= $item unless (s/\$item/$item/g); | ||||
38 | expandStandardEscapes($_) | ||||
39 | } @valueArray; | ||||
40 | } | ||||
41 | |||||
42 | # SMELL: the $separator is not being encoded | ||||
43 | $value = join( | ||||
44 | $separator, | ||||
45 | map { | ||||
46 | _handleURLPARAMValue( $_, $newLine, $encode, $default ) | ||||
47 | } @valueArray | ||||
48 | ); | ||||
49 | } | ||||
50 | else { | ||||
51 | $value = $default; | ||||
52 | $value = '' unless defined $value; | ||||
53 | } | ||||
54 | } | ||||
55 | else { | ||||
56 | 3 | 6µs | 3 | 57µs | $value = $this->{request}->param($param); # spent 57µs making 3 calls to Foswiki::Request::param, avg 19µs/call |
57 | 3 | 5µs | 3 | 11µs | $value = # spent 11µs making 3 calls to Foswiki::_handleURLPARAMValue, avg 4µs/call |
58 | _handleURLPARAMValue( $value, $newLine, $encode, $default ); | ||||
59 | } | ||||
60 | } | ||||
61 | 3 | 7µs | return $value; | ||
62 | } | ||||
63 | |||||
64 | # spent 11µs within Foswiki::_handleURLPARAMValue which was called 3 times, avg 4µs/call:
# 3 times (11µs+0s) by Foswiki::URLPARAM at line 57, avg 4µs/call | ||||
65 | 3 | 2µs | my ( $value, $newLine, $encode, $default ) = @_; | ||
66 | |||||
67 | 3 | 600ns | if ( defined $value ) { | ||
68 | $value =~ s/\r?\n/$newLine/g if ( defined $newLine ); | ||||
69 | if ( $encode =~ m/^entit(y|ies)$/i ) { | ||||
70 | $value = entityEncode($value); | ||||
71 | } | ||||
72 | elsif ( $encode =~ m/^quotes?$/i ) { | ||||
73 | $value =~ | ||||
74 | s/\"/\\"/g; # escape quotes with backslash (Bugs:Item3383 fix) | ||||
75 | } | ||||
76 | elsif ( $encode =~ m/^(off|none)$/i ) { | ||||
77 | |||||
78 | # no encoding | ||||
79 | } | ||||
80 | elsif ( $encode =~ m/^url$/i ) { | ||||
81 | |||||
82 | # Legacy, see ENCODE | ||||
83 | #$value =~ s/\r*\n\r*/<br \/>/; | ||||
84 | $value = urlEncode($value); | ||||
85 | } | ||||
86 | else { # safe or default | ||||
87 | # entity encode ' " < > and % | ||||
88 | $value =~ s/([<>%'"])/'&#'.ord($1).';'/ge; | ||||
89 | } | ||||
90 | } | ||||
91 | 3 | 1µs | unless ( defined $value ) { | ||
92 | 3 | 700ns | $value = $default; | ||
93 | 3 | 1µs | $value = '' unless defined $value; | ||
94 | } | ||||
95 | |||||
96 | # Block expansion of %URLPARAM in the value to prevent recursion | ||||
97 | 3 | 1µs | $value =~ s/%URLPARAM\{/%<nop>URLPARAM{/g; | ||
98 | 3 | 9µs | return $value; | ||
99 | } | ||||
100 | |||||
101 | 1 | 2µs | 1; | ||
102 | __END__ |