XLSX.pm

filter: Statementstmt 99.4% 346 / 348 Branchbran 92.1% 234 / 254 Conditioncond 82.1% 83 / 101 MC/DCmcdc 64.7% 33 / 51 Subroutinesub 100% 23 / 23 Podpod 0.0% 0 / 1 totaltotal 92.4% 719 / 778 CC 177 SCAR 36.9
CC
177
Cov
94%
_load_workbook
82.6
__xml_entity
22.0
__xml_contents
16.0
CRAP 39.9
« XLSX/Utility2007.pm ↑ Summary XLSX/Fmt2007.pm »
1 package Spreadsheet::XLSX;
2
3 26 ▶use 5.006000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 26 ▶use base 'Spreadsheet::ParseExcel::Workbook';
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 26 our $VERSION = '0.21';
10
11 26 our $MAX_MEMBER_SIZE = 64 * 1024 * 1024;
12 26 our $MAX_TOTAL_SIZE = 256 * 1024 * 1024;
13 26 our $MAX_MEMBERS = 10000;
14
15 26 ▶use Archive::Zip;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 26 ▶use Spreadsheet::ParseExcel;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 26 ▶use Spreadsheet::XLSX::Fmt2007;
Subroutine BEGIN: called CC=1 SCAR=0.0
18
19 ################################################################################
20
21 241 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
22 241 my ($class, $filename, $converter) = @_;
23
24 241 my %shared_info; # shared_strings, styles, style_info, rels, converter
25 241 $shared_info{converter} = $converter;
26
27 241 my $self = bless Spreadsheet::ParseExcel::Workbook->new(), $class;
28
29 241 my $zip = __load_zip($filename);
30
31 238 $shared_info{phonetics} = {};
32 238 $shared_info{shared_strings}= __load_shared_strings($zip, $shared_info{converter}, $shared_info{phonetics});
33 223 my ($styles, $style_info) = __load_styles($zip);
34 196 $shared_info{styles} = $styles;
35 196 $shared_info{style_info} = $style_info;
36 196 $shared_info{rels} = __load_rels($zip);
37
38 191 $self->_load_workbook($zip, \%shared_info);
39
40 139 return $self;
41 }
42
43 191 ▶sub _load_workbook {
Subroutine _load_workbook: called CC=80 SCAR=44.1
44 191 my ($self, $zip, $shared_info) = @_;
45
46 191 ▶ my $member_workbook = $zip->memberNamed('xl/workbook.xml') or die("xl/workbook.xml not found in this zip\n");
Branch: 1 branch
BranchTrueFalseTotal
my $member_workbook = $zip->memberNamed("xl/workbook.xml") or die "xl/workbook.xml not found in this zip\n" 191 0 191
47 191 $self->{SheetCount} = 0;
48 191 $self->{FmtClass} = Spreadsheet::XLSX::Fmt2007->new;
49 191 $self->{Flg1904} = 0;
50 191 my $workbook_xml = __xml_contents($member_workbook);
51 185 ▶ if ($workbook_xml =~ /date1904="1"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($workbook_xml =~ /date1904="1"/) 0 185 185
52 0 $self->{Flg1904} = 1;
53 }
54
55 185 foreach ($workbook_xml =~ /\<(.*?)\/?\>/g) {
56
57 1109 my ($tag, $attributes) = /^(\w+)\s+(.*)$/s;
58 1109 ▶ next unless defined($tag) && $tag eq 'sheet';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag and $tag eq "sheet" 915 194 1109
Condition100%3/3
defined $tag and $tag eq "sheet"
!ll&&!rl&&r
646269194
MC/DC100%2/2
defined $tag and $tag eq "sheet"
defined $tag $tag eq "sheet"
Truth table100%3/3
A and B
A= defined $tagB= $tag eq "sheet"
ABresult
0X0
100
111
59
60 194 my $sheet = {
61 MaxRow => 0,
62 MaxCol => 0,
63 MinRow => 1000000,
64 MinCol => 1000000,
65 };
66
67 194 foreach ($attributes =~ /(\S+=".*?")/gsm) {
68
69 579 my ($k, $v) = split /=?"/; #"
70
71 579 ▶ if ($k eq 'name') {
Branch: 2 branches
BranchTrueFalseTotal
if ($k eq 'name') { } 194 385 579
elsif ($k eq 'r:id') { } 191 194 385
72 194 $sheet->{Name} = __decode_xml_text($v);
73 192 ▶ $sheet->{Name} = $shared_info->{converter}->convert($sheet->{Name}) if defined $shared_info->{converter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $shared_info->{"converter"} 18 174 192
74 die "XLSX worksheet name conversion failed: the converter returned undef\n"
75 192 ▶ unless defined $sheet->{Name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sheet->{"Name"} 1 191 192
76 } elsif ($k eq 'r:id') {
77
78 191 $sheet->{_RelationshipId} = $v;
79 191 my $relation = $shared_info->{rels}->{$v};
80 191 ▶ $sheet->{path} = $relation->{Target} if $relation;
Branch: 1 branch
BranchTrueFalseTotal
if $relation 190 1 191
81
82 }
83
84 }
85
86 191 my $wsheet = Spreadsheet::ParseExcel::Worksheet->new(%$sheet);
87 191 $self->{Worksheet}[$self->{SheetCount}] = $wsheet;
88 191 $self->{SheetCount} += 1;
89
90 }
91
92
93 182 foreach my $sheet (@{$self->{Worksheet}}) {
94
95 191 my $id = $sheet->{_RelationshipId};
96 my $context = "worksheet '" . __diagnostic_text($sheet->{Name})
97 191 . "', relationship '" . __diagnostic_text($id) . "'";
98 191 ▶ my $relation = defined($id) ? $shared_info->{rels}->{$id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 191 0 191
99 191 ▶ die "Missing XLSX relationship for $context in xl/_rels/workbook.xml.rels\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $relation 1 190 191
100 unless $relation;
101 die "External XLSX target '" . __diagnostic_text($relation->{Target})
102 . "' is not supported for $context\n"
103 190 ▶ if defined($relation->{TargetMode}) && $relation->{TargetMode} eq 'External';
Branch: 1 branch
BranchTrueFalseTotal
if defined $relation->{"TargetMode"} and $relation->{"TargetMode"} eq "External" 2 188 190
Condition66%2/3
defined $relation->{"TargetMode"} and $relation->{"TargetMode"} eq "External"
!ll&&!rl&&r
18802
MC/DC50%1/2
defined $relation->{"TargetMode"} and $relation->{"TargetMode"} eq "External"
defined $relation->{"TargetMode"} $relation->{"TargetMode"} eq "External"
Truth table66%2/3
A and B
A= defined $relation->{"TargetMode"}B= $relation->{"TargetMode"} eq "External"
ABresult
0X0
100
111
104 # Keep the chartsheet placeholder without interpreting chart XML as cells.
105 188 ▶ next if defined($relation->{Type}) && $relation->{Type} =~ m{/chartsheet\z};
Branch: 1 branch
BranchTrueFalseTotal
if defined $relation->{"Type"} and $relation->{"Type"} =~ m[/chartsheet\z] 2 186 188
Condition100%3/3
defined $relation->{"Type"} and $relation->{"Type"} =~ m[/chartsheet\z]
!ll&&!rl&&r
96902
MC/DC100%2/2
defined $relation->{"Type"} and $relation->{"Type"} =~ m[/chartsheet\z]
defined $relation->{"Type"} $relation->{"Type"} =~ m[/chartsheet\z]
Truth table100%3/3
A and B
A= defined $relation->{"Type"}B= $relation->{"Type"} =~ m[/chartsheet\z]
ABresult
0X0
100
111
106 186 my $part = __resolve_part_target('xl/workbook.xml', $relation->{Target}, $context);
107 my $member_sheet = $zip->memberNamed($part)
108 or die "XLSX target '" . __diagnostic_text($relation->{Target})
109 181 ▶ . "' for $context resolves to missing ZIP member '$part'\n";
Branch: 1 branch
BranchTrueFalseTotal
my $member_sheet = $zip->memberNamed($part) or die q[XLSX target '] . __diagnostic_text($relation->{"Target"}) . "' for $context resolves to missing ZIP member '${part}'\n" 180 1 181
110
111 180 my ($row, $col);
112
113 180 my $parsing_v_tag = 0;
114 180 my $s = 0;
115 180 my $s2 = 0;
116 180 my $sty = 0;
117 180 my $inline = 0;
118 180 my $parsing_inline = 0;
119 180 my $inline_xml = '';
120 180 my @column_styles;
121 my $row_style;
122 180 my $sheet_xml = __xml_contents($member_sheet);
123 165 foreach ($sheet_xml =~ /(\<.*?\/?\>|.*?(?=\<))/gs) {
124 17670 ▶ if (/^<col(?:\s|\/?>)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (m[^<col(?:\s|/?>)]) { } 40 17630 17670
elsif (m[^<row(?:\s|/?>)]) { } 1074 16556 17630
elsif (m[^</row\s*>]) { } 1059 15497 16556
125 40 my %attributes = /\b(min|max|style)="([^"]*)"/g;
126 40 ▶ if (defined $attributes{style}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attributes{"style"}) 33 7 40
127 33 my ($min, $max) = @attributes{qw(min max)};
128 33 ▶ die "Invalid XLSX column style range in '" . $member_sheet->fileName() . "'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min and defined $max and $min =~ /\A[0-9]+\z/ and $max =~ /\A[0-9]+\z/ and $min >= 1 and $min <= $max and $max <= 16384 4 29 33
Condition61%11/18
defined $min and defined $max and $min =~ /\A[0-9]+\z/ and $max =~ /\A[0-9]+\z/ and $min >= 1 and $min <= $max and $max <= 16384
!ll&&!rl&&r
2229
defined $min and defined $max and $min =~ /\A[0-9]+\z/ and $max =~ /\A[0-9]+\z/ and $min >= 1 and $min <= $max
!ll&&!rl&&r
1131
defined $min and defined $max and $min =~ /\A[0-9]+\z/ and $max =~ /\A[0-9]+\z/ and $min >= 1
!ll&&!rl&&r
0132
defined $min and defined $max and $min =~ /\A[0-9]+\z/ and $max =~ /\A[0-9]+\z/
!ll&&!rl&&r
0033
defined $min and defined $max and $min =~ /\A[0-9]+\z/
!ll&&!rl&&r
0033
defined $min and defined $max
!ll&&!rl&&r
0033
MC/DC42%3/7
defined $min and defined $max and $min =~ /\A[0-9]+\z/ and $max =~ /\A[0-9]+\z/ and $min >= 1 and $min <= $max and $max <= 16384
defined $min defined $max $min =~ /\A[0-9]+\z/ $max =~ /\A[0-9]+\z/ $min >= 1 $min <= $max $max <= 16384
Truth table50%4/8
A and B and C and D and E and F and G
A= defined $minB= defined $maxC= $min =~ /\A[0-9]+\z/D= $max =~ /\A[0-9]+\z/E= $min >= 1F= $min <= $maxG= $max <= 16384
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
129 unless defined($min) && defined($max)
130 && $min =~ /\A[0-9]+\z/ && $max =~ /\A[0-9]+\z/
131 && $min >= 1 && $min <= $max && $max <= 16384;
132 die "Invalid XLSX column style index\n"
133 29 ▶ unless $attributes{style} =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attributes{"style"} =~ /\A[0-9]+\z/ 0 29 29
134 29 $column_styles[$_ - 1] = $attributes{style} for $min .. $max;
135 }
136 36 next;
137 } elsif (/^<row(?:\s|\/?>)/) {
138 1074 my %attributes = /\b(s|customFormat)="([^"]*)"/g;
139 1074 $row_style = undef;
140 1074 ▶ if (defined($attributes{s}) && defined($attributes{customFormat})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attributes{"s"} and defined $attributes{"customFormat"} and $attributes{"customFormat"} =~ /\A(?:1|true)\z/) 33 1041 1074
Condition83%5/6
defined $attributes{"s"} and defined $attributes{"customFormat"} and $attributes{"customFormat"} =~ /\A(?:1|true)\z/
!ll&&!rl&&r
1040133
defined $attributes{"s"} and defined $attributes{"customFormat"}
!ll&&!rl&&r
1040034
MC/DC66%2/3
defined $attributes{"s"} and defined $attributes{"customFormat"} and $attributes{"customFormat"} =~ /\A(?:1|true)\z/
defined $attributes{"s"} defined $attributes{"customFormat"} $attributes{"customFormat"} =~ /\A(?:1|true)\z/
Truth table75%3/4
A and B and C
A= defined $attributes{"s"}B= defined $attributes{"customFormat"}C= $attributes{"customFormat"} =~ /\A(?:1|true)\z/
ABCresult
0XX0
10X0
1100
1111
141 && $attributes{customFormat} =~ /\A(?:1|true)\z/) {
142 33 ▶ die "Invalid XLSX row style index\n" unless $attributes{s} =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attributes{"s"} =~ /\A[0-9]+\z/ 0 33 33
143 33 $row_style = $attributes{s};
144 }
145 1074 ▶ $row_style = undef if /\/>$/;
Branch: 1 branch
BranchTrueFalseTotal
if m[/>$] 0 1074 1074
146 1074 next;
147 } elsif (/^<\/row\s*>/) {
148 1059 $row_style = undef;
149 1059 next;
150 }
151 15497 ▶ if (/^<c(?:\s|\/?>)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^<c(?:\s|/?>)]) 5267 10230 15497
152
153 5267 my ($reference) = /\sr="([^"]*)"/;
154 ($row, $col) = __decode_cell_name($reference,
155 5267 "worksheet '" . __diagnostic_text($sheet->{Name}) . "' (" . $member_sheet->fileName() . ")");
156
157 5254 ▶ $s = m/t=\"s\"/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
/t=\"s\"/ ? : 1097 4157 5254
158 5254 ▶ $s2 = m/t=\"str\"/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
/t=\"str\"/ ? : 63 5191 5254
159 5254 my ($cell_style) = /\bs="([0-9]+)"/;
160 5254 ▶ $sty = defined($cell_style) ? $cell_style
Branch: 3 branches
BranchTrueFalseTotal
defined $cell_style ? : 2349 2905 5254
defined $row_style ? : 2 2903 2905
defined $column_styles[$col] ? : 2629 274 2903
161 : defined($row_style) ? $row_style
162 : defined($column_styles[$col]) ? $column_styles[$col] : 0;
163
164 5254 ▶ $inline = /\bt="inlineStr"/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
/\bt="inlineStr"/ ? : 68 5186 5254
165 5254 $parsing_v_tag = 0;
166 5254 $parsing_inline = 0;
167 5254 $inline_xml = '';
168 5254 next;
169 }
170
171 10230 ▶ if ($inline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline) { } 501 9729 10230
172 501 ▶ if (/^<is(?:\s[^<>]*?)?\s*\/?>$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (m[^<is(?:\s[^<>]*?)?\s*/?>$]) { } 68 433 501
elsif ($parsing_inline) { } 356 77 433
173 68 $inline_xml = '';
174 68 $parsing_inline = !/\/>$/;
175 68 ▶ next if $parsing_inline;
Branch: 1 branch
BranchTrueFalseTotal
if $parsing_inline 60 8 68
176 } elsif ($parsing_inline) {
177 356 ▶ if (/^<\/is\s*>$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^</is\s*>$]) { } 60 296 356
178 60 $parsing_inline = 0;
179 } else {
180 296 $inline_xml .= $_;
181 296 next;
182 }
183 } else {
184 77 next;
185 }
186 } else {
187 9729 ▶ if (/^<v(?:\s[^<>]*?)?>$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^<v(?:\s[^<>]*?)?>$/) { } 2190 7539 9729
elsif (m[^</v>]) { } 2188 5351 7539
188 2190 $parsing_v_tag = !/\/>$/;
189 2190 next;
190 } elsif (/^<\/v>/) {
191 2188 $parsing_v_tag = 0;
192 2188 next;
193 }
194 5351 ▶ next unless length($_) && $parsing_v_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ and $parsing_v_tag 3162 2189 5351
Condition66%2/3
length $_ and $parsing_v_tag
!ll&&!rl&&r
031622189
MC/DC50%1/2
length $_ and $parsing_v_tag
length $_ $parsing_v_tag
Truth table66%2/3
A and B
A= length $_B= $parsing_v_tag
ABresult
0X0
100
111
195 }
196
197 {
198 2257 my ($v, $phonetics);
199 2257 ▶ if ($inline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline) { } 68 2189 2257
200 68 ($v, $phonetics) = __parse_string($inline_xml, $shared_info->{converter});
201 } else {
202 2189 ▶ $v = $s ? $shared_info->{shared_strings}->[$_] : $_;
Branch: 1 branch
BranchTrueFalseTotal
$s ? : 1097 1092 2189
203 2189 ▶ $phonetics = $shared_info->{phonetics}->{$_} if $s;
Branch: 1 branch
BranchTrueFalseTotal
if $s 1097 1092 2189
204 }
205
206 2256 ▶ if (defined($v) && $v eq "</c>") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v eq "</c>") 0 2256 2256
Condition66%2/3
defined $v and $v eq "</c>"
!ll&&!rl&&r
422520
MC/DC0%0/2
defined $v and $v eq "</c>"
defined $v $v eq "</c>"
Truth table66%2/3
A and B
A= defined $vB= $v eq "</c>"
ABresult
0X0
100
111
207 0 $v = "";
208 }
209 2256 my $type = "Text";
210 2256 my $thisstyle = "";
211
212 2256 ▶ if (not($s) && not($s2) && not($inline)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s or $s2 or $inline) 1031 1225 2256
Condition100%6/6
$s or $s2 or $inline
l!l&&r!l&&!r
1158671031
$s or $s2
l!l&&r!l&&!r
1097611098
MC/DC100%3/3
$s or $s2 or $inline
$s $s2 $inline
Truth table100%4/4
A or B or C
A= $sB= $s2C= $inline
ABCresult
1XX1
01X1
0011
0000
213 1031 $type = "Numeric";
214
215 1031 ▶ if (defined $sty && defined $shared_info->{styles}->[$sty]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sty and defined $shared_info->{"styles"}[$sty]) 915 116 1031
Condition66%2/3
defined $sty and defined $shared_info->{"styles"}[$sty]
!ll&&!rl&&r
0116915
MC/DC50%1/2
defined $sty and defined $shared_info->{"styles"}[$sty]
defined $sty defined $shared_info->{"styles"}[$sty]
Truth table66%2/3
A and B
A= defined $styB= defined $shared_info->{"styles"}[$sty]
ABresult
0X0
100
111
216 915 $thisstyle = $shared_info->{style_info}->{$shared_info->{styles}->[$sty]};
217 # Literal text and escaped characters are not date tokens.
218 915 my $date_format = Spreadsheet::XLSX::Utility2007::unescape_HTML($thisstyle);
219 # Keep token boundaries when removing literal separators.
220 915 $date_format =~ s/"[^"]*"|\\.|_.|\*./ /g;
221 915 ▶ if ($date_format =~ /\b(?:m{1,5}|d{1,4}|y{2,4}|h{1,2}|s{1,2}|(?i:am\/pm|a\/p))\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date_format =~ m[\b(?:m{1,5}|d{1,4}|y{2,4}|h{1,2}|s{1,2}|(?i:am/pm|a/p))\b]) 64 851 915
222 64 $type = "Date";
223 }
224 }
225 }
226
227
228 2256 ▶ $sheet->{MaxRow} = $row if $sheet->{MaxRow} < $row;
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"MaxRow"} < $row 920 1336 2256
229 2256 ▶ $sheet->{MaxCol} = $col if $sheet->{MaxCol} < $col;
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"MaxCol"} < $col 79 2177 2256
230 2256 ▶ $sheet->{MinRow} = $row if $sheet->{MinRow} > $row;
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"MinRow"} > $row 150 2106 2256
231 2256 ▶ $sheet->{MinCol} = $col if $sheet->{MinCol} > $col;
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"MinCol"} > $col 150 2106 2256
232
233 2256 ▶ if ($type eq "Numeric" && defined($v) && $v =~ /(.*)E\-(.*)/gsm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Numeric" and defined $v and $v =~ /(.*)E\-(.*)/gms) 97 2159 2256
Condition83%5/6
$type eq "Numeric" and defined $v and $v =~ /(.*)E\-(.*)/gms
!ll&&!rl&&r
128987097
$type eq "Numeric" and defined $v
!ll&&!rl&&r
12890967
MC/DC66%2/3
$type eq "Numeric" and defined $v and $v =~ /(.*)E\-(.*)/gms
$type eq "Numeric" defined $v $v =~ /(.*)E\-(.*)/gms
Truth table75%3/4
A and B and C
A= $type eq "Numeric"B= defined $vC= $v =~ /(.*)E\-(.*)/gms
ABCresult
0XX0
10X0
1100
1111
234 97 $v = $1 / (10**$2); # this handles scientific notation for very small numbers
235 }
236
237 2256 my $cell = Spreadsheet::ParseExcel::Cell->new(
238 Val => $v,
239 Format => $thisstyle,
240 Type => $type
241 );
242
243 2256 ▶ if ($phonetics) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phonetics) 79 2177 2256
244 22 $cell->{RPh} = [map { { %$_ } } @{$phonetics->{RPh}}]
245 79 ▶ if exists $phonetics->{RPh};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phonetics->{"RPh"} 18 61 79
246 12 $cell->{PhoneticPr} = { %{$phonetics->{PhoneticPr}} }
247 79 ▶ if exists $phonetics->{PhoneticPr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $phonetics->{"PhoneticPr"} 12 67 79
248 }
249
250 2256 $cell->{_Value} = $self->{FmtClass}->ValFmt($cell, $self);
251 2255 ▶ if ($type eq "Date") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Date") 63 2192 2255
252 63 ▶ if ($v < 1) { #then this is Excel time field
Branch: 1 branch
BranchTrueFalseTotal
if ($v < 1) 5 58 63
253 5 $cell->{Type} = "Text";
254 5 $cell->{Val} = $cell->{_Value};
255 }
256 }
257 2255 $sheet->{Cells}[$row][$col] = $cell;
258 }
259 }
260
261 146 ▶ $sheet->{MinRow} = 0 if $sheet->{MinRow} > $sheet->{MaxRow};
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"MinRow"} > $sheet->{"MaxRow"} 8 138 146
262 146 ▶ $sheet->{MinCol} = 0 if $sheet->{MinCol} > $sheet->{MaxCol};
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"MinCol"} > $sheet->{"MaxCol"} 8 138 146
263
264 }
265
266 139 return $self;
267 }
268
269 # Validate before numeric conversion or using a reference as an array index.
270 # XLSX worksheets have at most 1,048,576 rows and 16,384 columns (XFD).
271
272 5267 ▶sub __decode_cell_name {
Subroutine __decode_cell_name: called CC=8 SCAR=20.8
273 5267 my ($reference, $context) = @_;
274 5267 ▶ my $details = defined($reference) ? "'" . __diagnostic_text($reference) . "'" : '(missing r attribute)';
Branch: 1 branch
BranchTrueFalseTotal
defined $reference ? : 5265 2 5267
275 5267 ▶ $details .= " in $context" if defined $context;
Branch: 1 branch
BranchTrueFalseTotal
if defined $context 5267 0 5267
276 5267 ▶ die "Invalid XLSX cell reference $details; expected an A1-style address from A1 to XFD1048576, not a defined name\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reference and $reference =~ /\A([A-Z]{1,3})([1-9][0-9]{0,6})\z/ 10 5257 5267
Condition100%3/3
defined $reference and $reference =~ /\A([A-Z]{1,3})([1-9][0-9]{0,6})\z/
!ll&&!rl&&r
285257
MC/DC100%2/2
defined $reference and $reference =~ /\A([A-Z]{1,3})([1-9][0-9]{0,6})\z/
defined $reference $reference =~ /\A([A-Z]{1,3})([1-9][0-9]{0,6})\z/
Truth table100%3/3
A and B
A= defined $referenceB= $reference =~ /\A([A-Z]{1,3})([1-9][0-9]{0,6})\z/
ABresult
0X0
100
111
277 unless defined($reference)
278 && $reference =~ /\A([A-Z]{1,3})([1-9][0-9]{0,6})\z/;
279 5257 my ($letters, $digits) = ($1, $2);
280 5257 ▶ die "XLSX cell row exceeds worksheet limit: $details; maximum row is 1048576\n" if $digits > 1048576;
Branch: 1 branch
BranchTrueFalseTotal
if $digits > 1048576 2 5255 5257
281
282 5255 my $col = 0;
283 5255 $col = $col * 26 + ord($_) - ord('A') + 1 for split //, $letters;
284 5255 ▶ die "XLSX cell column exceeds worksheet limit: $details; maximum column is XFD\n" if $col > 16384;
Branch: 1 branch
BranchTrueFalseTotal
if $col > 16384 1 5254 5255
285
286 5254 return ($digits - 1, $col - 1);
287 }
288
289
290 238 ▶sub __load_shared_strings {
Subroutine __load_shared_strings: called CC=5 SCAR=16.1
291 238 my ($zip, $converter, $phonetics) = @_;
292 238 ▶ $phonetics = {} unless defined $phonetics;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $phonetics 0 238 238
293
294 238 my $member_shared_strings = $zip->memberNamed('xl/sharedStrings.xml');
295
296 238 my @shared_strings = ();
297
298 238 ▶ if ($member_shared_strings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member_shared_strings) 74 164 238
299
300 74 my $mstr = __xml_contents($member_shared_strings);
301 66 $mstr =~ s/<t\/>/<t><\/t>/gsm; # this handles an empty t tag in the xml <t/>
302 66 foreach my $si ($mstr =~ /<si.*?>(.*?)<\/si/gsm) {
303 1014 my ($text, $metadata) = __parse_string($si, $converter);
304 1007 ▶ $phonetics->{scalar @shared_strings} = $metadata if keys %$metadata;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$metadata 10 997 1007
305 1007 push @shared_strings, $text;
306 }
307 }
308
309 223 return \@shared_strings;
310 }
311
312
313 # Shared strings (si) and inline strings (is) have the same text structure.
314 1082 ▶sub __parse_string {
Subroutine __parse_string: called CC=4 SCAR=13.9
315 1082 my ($xml, $converter) = @_;
316 1082 my %metadata;
317 my @runs;
318 1082 foreach my $run ($xml =~ /(<rPh\b[^>]*>.*?<\/rPh\s*>)/gs) {
319 19 my ($attributes, $text) = $run =~ /<rPh\b([^>]*)>(.*?)<\/rPh\s*>/s;
320 push @runs, {
321 19 %{__phonetic_attributes($attributes, qw(sb eb))},
322 Val => __shared_string_text($text, $converter),
323 };
324 }
325 1081 ▶ $metadata{RPh} = \@runs if @runs;
Branch: 1 branch
BranchTrueFalseTotal
if @runs 16 1065 1081
326 1081 ▶ if ($xml =~ /<phoneticPr\b([^>]*)>/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml =~ /<phoneticPr\b([^>]*)>/s) 10 1071 1081
327 10 $metadata{PhoneticPr} = __phonetic_attributes($1, qw(fontId type alignment));
328 }
329 # Phonetic runs contain their own t elements, not display text.
330 1081 $xml =~ s{<rPh\b[^>]*/>|<rPh\b[^>]*>.*?</rPh\s*>}{}gs;
331 1081 $xml =~ s{<t\b[^>]*/>}{<t></t>}gs;
332 1081 return (__shared_string_text($xml, $converter), \%metadata);
333 }
334
335 1100 ▶sub __shared_string_text {
Subroutine __shared_string_text: called CC=4 SCAR=13.9
336 1100 my ($xml, $converter) = @_;
337 1100 my $str = '';
338 1100 foreach my $text ($xml =~ /<t\b[^>]*>(.*?)<\/t\s*>/gs) {
339 # Decode each XML fragment exactly once, before character conversion.
340 # Decoding after concatenation would also reinterpret literal entities
341 # assembled across rich-text runs.
342 1120 $text = __decode_xml_text($text);
343 1115 ▶ $text = $converter->convert($text) if defined $converter;
Branch: 1 branch
BranchTrueFalseTotal
if defined $converter 87 1028 1115
344 1115 ▶ die "XLSX text conversion failed: the converter returned undef\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 3 1112 1115
345 unless defined $text;
346 1112 $str .= $text;
347 }
348 1092 return $str;
349 }
350
351 1314 ▶sub __decode_xml_text {
Subroutine __decode_xml_text: called CC=1 SCAR=0.0
352 1314 my ($text) = @_;
353 1314 $text =~ s/&((?:amp|lt|gt|quot|apos)|\#[0-9]+|\#x[0-9A-Fa-f]+);/__xml_entity($1)/ge;
354 1307 return $text;
355 }
356
357 153 ▶sub __xml_entity {
Subroutine __xml_entity: called CC=22 SCAR=30.9
358 153 my ($entity) = @_;
359 153 ▶ return '&' if $entity eq 'amp';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "amp" 40 113 153
360 113 ▶ return '<' if $entity eq 'lt';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "lt" 6 107 113
361 107 ▶ return '>' if $entity eq 'gt';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "gt" 6 101 107
362 101 ▶ return '"' if $entity eq 'quot';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "quot" 8 93 101
363 93 ▶ return "'" if $entity eq 'apos';
Branch: 1 branch
BranchTrueFalseTotal
if $entity eq "apos" 8 85 93
364
365 85 my $digits = substr($entity, 1);
366 85 my $hex = $digits =~ s/\Ax//;
367 85 $digits =~ s/\A0+//;
368 85 ▶ $digits = '0' unless length $digits;
Branch: 1 branch
BranchTrueFalseTotal
unless length $digits 2 83 85
369 85 my $error = "Invalid XML character reference '&" . __diagnostic_text($entity) . ";' in XLSX string\n";
370 85 ▶ die $error if length($digits) > ($hex ? 6 : 7);
Branch: 2 branches
BranchTrueFalseTotal
if length $digits > ($hex ? 6 : 7) 1 84 85
$hex ? : 35 50 85
371 84 ▶ my $code = $hex ? hex($digits) : 0 + $digits;
Branch: 1 branch
BranchTrueFalseTotal
$hex ? : 35 49 84
372 84 ▶ die $error unless $code == 9 || $code == 10 || $code == 13
Branch: 1 branch
BranchTrueFalseTotal
unless $code == 9 or $code == 10 or $code == 13 or $code >= 32 and $code <= 55295 or $code >= 57344 and $code <= 65533 or $code >= 65536 and $code <= 1114111 6 78 84
Condition91%22/24
$code == 9 or $code == 10 or $code == 13 or $code >= 32 and $code <= 55295 or $code >= 57344 and $code <= 65533 or $code >= 65536 and $code <= 1114111
l!l&&r!l&&!r
7086
$code == 9 or $code == 10 or $code == 13 or $code >= 32 and $code <= 55295 or $code >= 57344 and $code <= 65533
l!l&&r!l&&!r
70014
$code == 9 or $code == 10 or $code == 13 or $code >= 32 and $code <= 55295
l!l&&r!l&&!r
125814
$code == 9 or $code == 10 or $code == 13
l!l&&r!l&&!r
8472
$code == 9 or $code == 10
l!l&&r!l&&!r
4476
$code >= 32 and $code <= 55295
!ll&&!rl&&r
21258
$code >= 57344 and $code <= 65533
!ll&&!rl&&r
4100
$code >= 65536 and $code <= 1114111
!ll&&!rl&&r
428
MC/DC66%6/9
$code == 9 or $code == 10 or $code == 13 or $code >= 32 and $code <= 55295 or $code >= 57344 and $code <= 65533 or $code >= 65536 and $code <= 1114111
$code == 9 $code == 10 $code == 13 $code >= 32 $code <= 55295 $code >= 57344 $code <= 65533 $code >= 65536 $code <= 1114111
Truth table44%8/18
A or B or C or D and E or F and G or H and I
A= $code == 9B= $code == 10C= $code == 13D= $code >= 32E= $code <= 55295F= $code >= 57344G= $code <= 65533H= $code >= 65536I= $code <= 1114111
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
00011XXXX1
0000X11XX1
0001011XX1
0000X0X111
0000X10111
000100X111
0001010111
0000X0X0X0
0000X0X100
0000X100X0
0000X10100
000100X0X0
000100X100
00010100X0
0001010100
373 || ($code >= 0x20 && $code <= 0xd7ff)
374 || ($code >= 0xe000 && $code <= 0xfffd)
375 || ($code >= 0x10000 && $code <= 0x10ffff);
376
377 # ZIP XML and the optional converter use UTF-8 bytes, not Perl characters.
378 # Keep numeric references consistent with literal UTF-8 text, without
379 # adding an encoding-library dependency or changing the minimum Perl.
380 78 ▶ return pack('C', $code) if $code < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $code < 128 46 32 78
381 32 ▶ return pack('C*', 0xc0 | ($code >> 6), 0x80 | ($code & 0x3f)) if $code < 0x800;
Branch: 1 branch
BranchTrueFalseTotal
if $code < 2048 10 22 32
382 22 ▶ return pack('C*', 0xe0 | ($code >> 12), 0x80 | (($code >> 6) & 0x3f),
Branch: 1 branch
BranchTrueFalseTotal
if $code < 65536 14 8 22
383 0x80 | ($code & 0x3f)) if $code < 0x10000;
384 8 return pack('C*', 0xf0 | ($code >> 18), 0x80 | (($code >> 12) & 0x3f),
385 0x80 | (($code >> 6) & 0x3f), 0x80 | ($code & 0x3f));
386 }
387
388 29 ▶sub __phonetic_attributes {
Subroutine __phonetic_attributes: called CC=4 SCAR=14.0
389 29 my ($xml, @fields) = @_;
390 29 my %wanted = map { $_ => 1 } @fields;
391 29 my %attributes;
392 29 ▶ while ($xml =~ /([A-Za-z][A-Za-z0-9]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml =~ /([A-Za-z][A-Za-z0-9]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g) 58 29 87
393 58 ▶ my ($key, $value) = ($1, defined($2) ? $2 : $3);
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 58 0 58
394 58 ▶ $attributes{ucfirst($key)} = $value if $wanted{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $wanted{$key} 58 0 58
395 }
396 29 return \%attributes;
397 }
398
399 223 ▶sub __load_styles {
Subroutine __load_styles: called CC=10 SCAR=23.1
400 223 my ($zip) = @_;
401
402 223 my $member_styles = $zip->memberNamed('xl/styles.xml');
403
404 223 my @styles = ();
405 223 my %style_info = ();
406
407 223 ▶ if ($member_styles) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member_styles) 91 132 223
408 91 my $formatter = Spreadsheet::XLSX::Fmt2007->new();
409 91 my $styles_xml = __xml_contents($member_styles);
410
411 # IDs from both format declarations and style references are data,
412 # never regular-expression syntax.
413 86 foreach my $id ($styles_xml =~ /\bnumFmtId="([^"]*)"/g) {
414 558 ▶ die "Invalid XLSX number format ID\n" unless $id =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /\A[0-9]+\z/ 22 536 558
415 }
416
417 64 foreach my $t ($styles_xml =~ /xf\ numFmtId="([^"]*)"(?!.*\/cellStyleXfs)/gsm) { #"
418 243 push @styles, $t;
419 }
420
421 64 foreach my $t1 (@styles) {
422 # A repeated format ID still refers to the same explicit format.
423 # List context avoids reusing $1 from an earlier successful match.
424 243 my ($formatCode) = $styles_xml =~ /numFmtId="\Q$t1\E" formatCode="([^"]*)/;
425 243 ▶ if (!defined($formatCode) || $formatCode eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $formatCode or $formatCode eq "") 195 48 243
Condition66%2/3
not defined $formatCode or $formatCode eq ""
l!l&&r!l&&!r
195048
MC/DC50%1/2
not defined $formatCode or $formatCode eq ""
not defined $formatCode $formatCode eq ""
Truth table66%2/3
not(A) or B
A= not defined $formatCodeB= $formatCode eq ""
ABresult
1X1
011
000
426 # Retain the existing General fallback for ID 0. Other
427 # built-in IDs use the formatter's existing definition table.
428 195 ▶ $formatCode = $t1 == 0 ? '' : ($formatter->FmtStringDef($t1, {}) || '');
Branch: 1 branch
BranchTrueFalseTotal
$t1 == 0 ? : 119 76 195
Condition50%1/2
$formatter->FmtStringDef($t1, {}) or ""
l!l
760
MC/DC0%0/1
$formatter->FmtStringDef($t1, {}) or ""
$formatter->FmtStringDef($t1, {})
Truth table50%1/2
A
A= $formatter->FmtStringDef($t1, {})
Aresult
11
00
429 }
430 243 $style_info{$t1} = $formatCode;
431 }
432
433 }
434 196 return (\@styles, \%style_info);
435 }
436
437
438 196 ▶sub __load_rels {
Subroutine __load_rels: called CC=4 SCAR=14.0
439 196 my ($zip) = @_;
440
441 196 ▶ my $member_rels = $zip->memberNamed('xl/_rels/workbook.xml.rels') or die("xl/_rels/workbook.xml.rels not found in this zip\n");
Branch: 1 branch
BranchTrueFalseTotal
my $member_rels = $zip->memberNamed("xl/_rels/workbook.xml.rels") or die "xl/_rels/workbook.xml.rels not found in this zip\n" 196 0 196
442
443 196 my %rels = ();
444
445 196 my $rels_xml = __xml_contents($member_rels);
446 191 foreach ($rels_xml =~ /\<Relationship\s+(.*?)\/?\>/gs) {
447
448 302 my %attributes = /\b(Id|Target|TargetMode|Type)="([^"]*)"/g;
449 302 ▶ if (defined $attributes{Id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attributes{"Id"}) 302 0 302
450 302 $rels{$attributes{Id}} = \%attributes;
451 }
452
453 }
454
455 191 return \%rels;
456 }
457
458 186 ▶sub __resolve_part_target {
Subroutine __resolve_part_target: called CC=12 SCAR=24.9
459 186 my ($source, $target, $context) = @_;
460 186 ▶ my $shown = defined($target) ? "'" . __diagnostic_text($target) . "'" : '(missing Target attribute)';
Branch: 1 branch
BranchTrueFalseTotal
defined $target ? : 185 1 186
461 186 ▶ die "Invalid XLSX package target $shown for $context\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and length $target and not $target =~ m[\A(?:[A-Za-z][A-Za-z0-9+.-]*:|//)|[\\?#]] 3 183 186
Condition100%6/6
defined $target and length $target and not $target =~ m[\A(?:[A-Za-z][A-Za-z0-9+.-]*:|//)|[\\?#]]
!ll&&!rl&&r
21183
defined $target and length $target
!ll&&!rl&&r
11184
MC/DC100%3/3
defined $target and length $target and not $target =~ m[\A(?:[A-Za-z][A-Za-z0-9+.-]*:|//)|[\\?#]]
defined $target length $target not $target =~ m[\A(?:[A-Za-z][A-Za-z0-9+.-]*:|//)|[\\?#]]
Truth table100%4/4
A and B and not(C)
A= defined $targetB= length $targetC= not $target =~ m[\A(?:[A-Za-z][A-Za-z0-9+.-]*:|//)|[\\?#]]
ABCresult
0XX0
10X0
1100
1111
462 unless defined($target) && length($target)
463 && $target !~ m{\A(?:[A-Za-z][A-Za-z0-9+.-]*:|//)|[\\?#]};
464 183 $source =~ s{[^/]*\z}{};
465 183 ▶ my @parts = $target =~ m{\A/} ? () : grep { length } split '/', $source;
Branch: 1 branch
BranchTrueFalseTotal
$target =~ m[\A/] ? : 13 170 183
466 183 for my $segment (split '/', $target) {
467 438 ▶ next if $segment eq '' || $segment eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $segment eq "" or $segment eq "." 25 413 438
Condition100%3/3
$segment eq "" or $segment eq "."
l!l&&r!l&&!r
1312413
MC/DC100%2/2
$segment eq "" or $segment eq "."
$segment eq "" $segment eq "."
Truth table100%3/3
A or B
A= $segment eq ""B= $segment eq "."
ABresult
1X1
011
000
468 413 ▶ if ($segment eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($segment eq '..') { } 21 392 413
469 21 ▶ die "XLSX package target $shown for $context escapes the package root\n" unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 2 19 21
470 19 pop @parts;
471 } else {
472 392 push @parts, $segment;
473 }
474 }
475 181 ▶ die "Invalid XLSX package target $shown for $context: no ZIP member path\n" unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 0 181 181
476 181 return join '/', @parts;
477 }
478
479 241 ▶sub __load_zip {
Subroutine __load_zip: called CC=8 SCAR=20.8
480 241 my ($filename) = @_;
481
482 241 my $zip = Archive::Zip->new();
483
484 241 ▶ if (ref $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filename) { } 2 239 241
485 2 ▶ $zip->readFromFileHandle($filename) == Archive::Zip::AZ_OK or die("Cannot open data as Zip archive");
Branch: 1 branch
BranchTrueFalseTotal
$zip->readFromFileHandle($filename) == 0 or die "Cannot open data as Zip archive" 2 0 2
486 } else {
487 239 ▶ $zip->read($filename) == Archive::Zip::AZ_OK or die("Cannot open $filename as Zip archive");
Branch: 1 branch
BranchTrueFalseTotal
$zip->read($filename) == 0 or die "Cannot open $filename as Zip archive" 239 0 239
488 }
489
490 241 my @members = $zip->members();
491 241 ▶ die "XLSX ZIP entry count exceeds limit\n" if @members > $MAX_MEMBERS;
Branch: 1 branch
BranchTrueFalseTotal
if @members > $Spreadsheet::XLSX::MAX_MEMBERS 1 240 241
492 240 my $total = 0;
493 240 foreach my $member (@members) {
494 1001 my $size = $member->uncompressedSize();
495 1001 ▶ die "XLSX ZIP member size exceeds limit\n" if $size > $MAX_MEMBER_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
if $size > $Spreadsheet::XLSX::MAX_MEMBER_SIZE 1 1000 1001
496 1000 $total += $size;
497 1000 ▶ die "XLSX ZIP total size exceeds limit\n" if $total > $MAX_TOTAL_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
if $total > $Spreadsheet::XLSX::MAX_TOTAL_SIZE 1 999 1000
498 }
499
500 238 return $zip;
501 }
502
503 11922 ▶sub __diagnostic_text {
Subroutine __diagnostic_text: called CC=3 SCAR=11.0
504 11922 my ($text) = @_;
505 11922 ▶ $text = '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 11922 11922
506 11922 ▶ $text = substr($text, 0, 80) . '...' if length($text) > 80;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > 80 1 11921 11922
507 11922 $text =~ s/[\x00-\x1f\x7f]/?/g;
508 11922 return $text;
509 }
510
511 # Recognize only the markup needed for diagnostics. This is deliberately not
512 # a validating XML parser: it does not check nesting, entities or namespaces.
513 732 ▶sub __xml_contents {
Subroutine __xml_contents: called CC=16 SCAR=27.7
514 732 my ($member) = @_;
515 732 my $xml = __member_contents($member);
516 721 my $name = __diagnostic_text($member->fileName());
517 721 my %data_elements = map { $_ => 1 } qw(
518 workbook sheets sheet worksheet sheetData row c v f is
519 sst si r t rPh phoneticPr styleSheet numFmts numFmt cellStyleXfs cellXfs xf
520 Relationships Relationship
521 );
522 721 pos($xml) = 0;
523 721 ▶ while (pos($xml) < length($xml)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $xml < length $xml) 28445 693 29138
524 28445 ▶ next if $xml =~ /\G[^<]+/gc;
Branch: 1 branch
BranchTrueFalseTotal
if $xml =~ /\G[^<]+/cg 3496 24949 28445
525 24949 my $offset = pos($xml);
526 24949 ▶ if (substr($xml, $offset, 4) eq '<!--') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($xml, $offset, 4) eq "<!--") 2 24947 24949
527 2 ▶ next if $xml =~ /\G<!--.*?-->/gcs;
Branch: 1 branch
BranchTrueFalseTotal
if $xml =~ /\G<!--.*?-->/cgs 1 1 2
528 1 die "Cannot parse XLSX XML member '$name': unterminated XML comment at byte $offset\n";
529 }
530 24947 ▶ if (substr($xml, $offset, 9) eq '<![CDATA[') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($xml, $offset, 9) eq "<![CDATA[") 2 24945 24947
531 2 ▶ next if $xml =~ /\G<!\[CDATA\[.*?\]\]>/gcs;
Branch: 1 branch
BranchTrueFalseTotal
if $xml =~ /\G<!\[CDATA\[.*?\]\]>/cgs 1 1 2
532 1 die "Cannot parse XLSX XML member '$name': unterminated CDATA section at byte $offset\n";
533 }
534 24945 ▶ if (substr($xml, $offset, 2) eq '<?') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($xml, $offset, 2) eq "<?") 48 24897 24945
535 48 ▶ next if $xml =~ /\G<\?.*?\?>/gcs;
Branch: 1 branch
BranchTrueFalseTotal
if $xml =~ /\G<\?.*?\?>/cgs 47 1 48
536 1 die "Cannot parse XLSX XML member '$name': unterminated processing instruction at byte $offset\n";
537 }
538 24897 ▶ die "Cannot parse XLSX XML member '$name': DOCTYPE declarations are not supported\n"
Branch: 1 branch
BranchTrueFalseTotal
if $xml =~ /\G<!DOCTYPE\b/cg 2 24895 24897
539 if $xml =~ /\G<!DOCTYPE\b/gc;
540 24895 ▶ $xml =~ /\G(<(?:[^<>"']|"[^"<]*"|'[^'<]*')*>)/gcs
Branch: 1 branch
BranchTrueFalseTotal
$xml =~ /\G(<(?:[^<>"']|"[^"<]*"|'[^'<]*')*>)/cgs or die "Cannot parse XLSX XML member '${name}': unterminated or malformed XML tag at byte $offset\n" 24889 6 24895
541 or die "Cannot parse XLSX XML member '$name': unterminated or malformed XML tag at byte $offset\n";
542 24889 my $tag = $1;
543 24889 my ($closing, $element, $attributes) = $tag =~ /\A<(\/?)([A-Za-z_][A-Za-z0-9_.:-]*)(.*?)>\z/s;
544 24889 ▶ die "Cannot parse XLSX XML member '$name': malformed XML tag at byte $offset\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element 1 24888 24889
545 unless defined $element;
546 24888 ▶ my $valid = $closing ? $attributes =~ /\A\s*\z/
Branch: 1 branch
BranchTrueFalseTotal
$closing ? : 9787 15101 24888
547 : $attributes =~ /\A(?:\s+[A-Za-z_][A-Za-z0-9_.:-]*\s*=\s*(?:"[^"<]*"|'[^'<]*'))*\s*\/?\z/s;
548 24888 ▶ die "Cannot parse XLSX XML member '$name': malformed attributes in element '$element' at byte $offset\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 2 24886 24888
549 unless $valid;
550 die "Unsupported namespace-prefixed element '" . __diagnostic_text($element)
551 . "' in XLSX XML member '$name'. Prefixes can be valid XLSX, but are not supported by Spreadsheet::XLSX. Use Spreadsheet::ParseXLSX for namespace-prefixed files.\n"
552 24886 ▶ if $element =~ /:([^:]+)\z/ && $data_elements{$1};
Branch: 1 branch
BranchTrueFalseTotal
if $element =~ /:([^:]+)\z/ and $data_elements{$1} 14 24872 24886
Condition100%3/3
$element =~ /:([^:]+)\z/ and $data_elements{$1}
!ll&&!rl&&r
248591314
MC/DC100%2/2
$element =~ /:([^:]+)\z/ and $data_elements{$1}
$element =~ /:([^:]+)\z/ $data_elements{$1}
Truth table100%3/3
A and B
A= $element =~ /:([^:]+)\z/B= $data_elements{$1}
ABresult
0X0
100
111
553 }
554 693 return $xml;
555 }
556
557 # readChunk() limits compressed input, not inflated output. Small input chunks
558 # bound temporary inflate buffers; check output before appending it. Never trust
559 # central-directory sizes alone: actual output must not exceed the declared size.
560 732 ▶sub __member_contents {
Subroutine __member_contents: called CC=10 SCAR=23.1
561 732 my ($member) = @_;
562 732 my $declared = $member->uncompressedSize();
563 732 ▶ die "XLSX ZIP member size exceeds limit\n" if $declared > $MAX_MEMBER_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
if $declared > $Spreadsheet::XLSX::MAX_MEMBER_SIZE 0 732 732
564 732 my $old_method = $member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED);
565 732 my $contents = '';
566 732 my $ok = eval {
567 732 ▶ die "Cannot read XLSX ZIP member\n" unless $member->rewindData() == Archive::Zip::AZ_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $member->rewindData == 0 0 732 732
568 732 while (1) {
569 1416 my ($buffer, $status) = $member->readChunk(1024);
570 1416 ▶ die "Cannot read XLSX ZIP member\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 0 or $status == 1 0 1416 1416
Condition66%2/3
$status == 0 or $status == 1
l!l&&r!l&&!r
6847320
MC/DC0%0/2
$status == 0 or $status == 1
$status == 0 $status == 1
Truth table66%2/3
A or B
A= $status == 0B= $status == 1
ABresult
1X1
011
000
571 unless $status == Archive::Zip::AZ_OK || $status == Archive::Zip::AZ_STREAM_END;
572 1416 my $size = length($contents) + length($$buffer);
573 1416 ▶ die "XLSX ZIP member size exceeds limit\n" if $size > $MAX_MEMBER_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
if $size > $Spreadsheet::XLSX::MAX_MEMBER_SIZE 1 1415 1416
574 1415 ▶ die "XLSX ZIP member size does not match metadata\n" if $size > $declared;
Branch: 1 branch
BranchTrueFalseTotal
if $size > $declared 5 1410 1415
575 1410 $contents .= $$buffer;
576 1410 ▶ last if $status == Archive::Zip::AZ_STREAM_END;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 1 726 684 1410
577 }
578 726 ▶ die "XLSX ZIP member size does not match metadata\n" if length($contents) != $declared;
Branch: 1 branch
BranchTrueFalseTotal
if length $contents != $declared 5 721 726
579 721 1;
580 };
581 732 my $error = $@;
582 732 $member->endRead();
583 732 $member->desiredCompressionMethod($old_method);
584 732 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 11 721 732
585 721 return $contents;
586 }
587
588
589 26 1;
590 __END__
« XLSX/Utility2007.pm ↑ Summary XLSX/Fmt2007.pm »