Skip to content

Commit d6e3ceb

Browse files
committed
conditional format: fix failed match for range string
Strings used in a cell equality must be quoted. In order to ensure this there is a check for non-range/non-numeric strings. However this test wasn't anchored properly and gave a false positive. Issue #312
1 parent 493894e commit d6e3ceb

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

lib/Excel/Writer/XLSX/Worksheet.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10275,7 +10275,7 @@ sub _write_cf_rule {
1027510275
my $value = $param->{value};
1027610276

1027710277
# String "Cell" values must be quoted, apart from ranges.
10278-
if ( $value !~ /(\$?)([A-Z]{1,3})(\$?)(\d+)/
10278+
if ( $value !~ /^(\$?)([A-Z]{1,3})(\$?)(\d+)/
1027910279
&& $value !~
1028010280
/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ )
1028110281
{
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
###############################################################################
2+
#
3+
# Tests for Excel::Writer::XLSX::Worksheet methods.
4+
#
5+
# Copyright 2000-2024, John McNamara, jmcnamara@cpan.org
6+
#
7+
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
8+
#
9+
10+
use lib 't/lib';
11+
use TestFunctions qw(_expected_to_aref _got_to_aref _is_deep_diff _new_worksheet);
12+
use strict;
13+
use warnings;
14+
15+
use Test::More tests => 1;
16+
17+
###############################################################################
18+
#
19+
# Tests setup.
20+
#
21+
my $expected;
22+
my $got;
23+
my $caption;
24+
my $worksheet;
25+
26+
27+
###############################################################################
28+
#
29+
# Test the _assemble_xml_file() method.
30+
#
31+
# Test conditional formats.
32+
#
33+
$caption = " \tWorksheet: _assemble_xml_file()";
34+
35+
$worksheet = _new_worksheet(\$got);
36+
37+
$worksheet->select();
38+
39+
# Start test code.
40+
$worksheet->conditional_formatting( 'A1',
41+
{
42+
type => 'cell',
43+
format => undef,
44+
criteria => '==',
45+
value => 'Test A2',
46+
}
47+
);
48+
# End test code.
49+
50+
$worksheet->_assemble_xml_file();
51+
52+
$expected = _expected_to_aref();
53+
$got = _got_to_aref( $got );
54+
55+
_is_deep_diff( $got, $expected, $caption );
56+
57+
__DATA__
58+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
59+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
60+
<dimension ref="A1"/>
61+
<sheetViews>
62+
<sheetView tabSelected="1" workbookViewId="0"/>
63+
</sheetViews>
64+
<sheetFormatPr defaultRowHeight="15"/>
65+
<sheetData/>
66+
<conditionalFormatting sqref="A1">
67+
<cfRule type="cellIs" priority="1" operator="equal">
68+
<formula>"Test A2"</formula>
69+
</cfRule>
70+
</conditionalFormatting>
71+
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
72+
</worksheet>

0 commit comments

Comments
 (0)