Skip to content

Commit

Permalink
Make XML encoding the default. Fixes #43 and other.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Nov 18, 2012
1 parent 11b7503 commit e52a838
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/Excel/Writer/XLSX/Chart.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ sub _write_number_format {
'sourceLinked' => $source_linked,
);

$self->xml_encoded_empty_tag( 'c:numFmt', @attributes );
$self->xml_empty_tag( 'c:numFmt', @attributes );
}


Expand Down Expand Up @@ -2437,7 +2437,7 @@ sub _write_cat_number_format {
'sourceLinked' => $source_linked,
);

$self->xml_encoded_empty_tag( 'c:numFmt', @attributes );
$self->xml_empty_tag( 'c:numFmt', @attributes );
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Excel/Writer/XLSX/Drawing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ sub _write_txBody {

$self->xml_end_tag( 'a:rPr' );

$self->xml_encoded_data_element( 'a:t', $shape->{_text} );
$self->xml_data_element( 'a:t', $shape->{_text} );

$self->xml_end_tag( 'a:r' );
$self->xml_end_tag( 'a:p' );
Expand Down
2 changes: 1 addition & 1 deletion lib/Excel/Writer/XLSX/Package/Relationships.pm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ sub _write_relationship {

push @attributes, ( 'TargetMode' => $target_mode ) if $target_mode;

$self->xml_encoded_empty_tag( 'Relationship', @attributes );
$self->xml_empty_tag( 'Relationship', @attributes );
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Excel/Writer/XLSX/Package/Styles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ sub _write_num_fmt {
'formatCode' => $format_code,
);

$self->xml_encoded_empty_tag( 'numFmt', @attributes );
$self->xml_empty_tag( 'numFmt', @attributes );
}


Expand Down
40 changes: 17 additions & 23 deletions lib/Excel/Writer/XLSX/Package/XMLwriter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ our $VERSION = '0.55';
#
# NOTE: this module is a light weight re-implementation of XML::Writer. See
# the Pod docs below for a full explanation. The methods are implemented
# for speed rather than readibility since they are used heavily in tight
# for speed rather than readability since they are used heavily in tight
# loops by Excel::Writer::XLSX.
#

Expand Down Expand Up @@ -59,7 +59,7 @@ sub new {
# _set_xml_writer()
#
# Set the XML writer filehandle for the object. This can either be done
# in the constuctor (usually for testing since the file name isn't generally
# in the constructor (usually for testing since the file name isn't generally
# known at that stage) or later via this method.
#
sub _set_xml_writer {
Expand Down Expand Up @@ -97,8 +97,7 @@ sub xml_declaration {
#
# xml_start_tag()
#
# Write an XML start tag with optional attributes. As an optimisation the
# attributes aren't encoded by default: the most common case.
# Write an XML start tag with optional attributes.
#
sub xml_start_tag {

Expand All @@ -108,6 +107,7 @@ sub xml_start_tag {
while ( @_ ) {
my $key = shift @_;
my $value = shift @_;
$value = _escape_attributes( $value );

$tag .= qq( $key="$value");
}
Expand All @@ -119,19 +119,19 @@ sub xml_start_tag {

###############################################################################
#
# xml_start_tag()
# xml_start_tag_unencoded()
#
# Write an XML start tag with optional, encoded, attributes.
# Write an XML start tag with optional, unencoded, attributes.
# This is a minor speed optimisation for elements that don't need encoding.
#
sub xml_start_tag_encoded {
sub xml_start_tag_unencoded {

my $self = shift;
my $tag = shift;

while ( @_ ) {
my $key = shift @_;
my $value = shift @_;
$value = _escape_attributes( $value );

$tag .= qq( $key="$value");
}
Expand Down Expand Up @@ -184,19 +184,19 @@ sub xml_empty_tag {

###############################################################################
#
# xml_encoded_empty_tag()
# xml_empty_tag_unencoded()
#
# Write an empty XML tag with optional encoded attributes.
# Write an empty XML tag with optional, unencoded, attributes.
# This is a minor speed optimisation for elements that don't need encoding.
#
sub xml_encoded_empty_tag {
sub xml_empty_tag_unencoded {

my $self = shift;
my $tag = shift;

while ( @_ ) {
my $key = shift @_;
my $value = shift @_;
$value = _escape_attributes( $value );

$tag .= qq( $key="$value");
}
Expand Down Expand Up @@ -224,6 +224,7 @@ sub xml_data_element {
while ( @_ ) {
my $key = shift @_;
my $value = shift @_;
$value = _escape_attributes( $value );

$tag .= qq( $key="$value");
}
Expand All @@ -237,12 +238,12 @@ sub xml_data_element {

###############################################################################
#
# xml_encoded_data_element()
# xml_data_element_unencoded()
#
# Write an XML element containing data with optional, encoded, attributes.
# XML characters in the data are encoded.
# Write an XML unencoded element containing data with optional attributes.
# This is a minor speed optimisation for elements that don't need encoding.
#
sub xml_encoded_data_element {
sub xml_data_element_unencoded {

my $self = shift;
my $tag = shift;
Expand All @@ -252,13 +253,10 @@ sub xml_encoded_data_element {
while ( @_ ) {
my $key = shift @_;
my $value = shift @_;
$value = _escape_attributes( $value );

$tag .= qq( $key="$value");
}

$data = _escape_data( $data );

local $\ = undef;
print { $self->{_fh} } "<$tag>$data</$end_tag>";
}
Expand Down Expand Up @@ -470,8 +468,6 @@ sub _escape_attributes {
}




###############################################################################
#
# _escape_data()
Expand All @@ -495,8 +491,6 @@ sub _escape_data {
}




1;


Expand Down
2 changes: 1 addition & 1 deletion lib/Excel/Writer/XLSX/Workbook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ sub _write_sheet {
push @attributes, ( 'r:id' => $r_id );


$self->xml_encoded_empty_tag( 'sheet', @attributes );
$self->xml_empty_tag( 'sheet', @attributes );
}


Expand Down
14 changes: 7 additions & 7 deletions lib/Excel/Writer/XLSX/Worksheet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6277,10 +6277,10 @@ sub _write_row {
}
if ( $empty_row ) {
$self->xml_empty_tag( 'row', @attributes );
$self->xml_empty_tag_unencoded( 'row', @attributes );
}
else {
$self->xml_start_tag( 'row', @attributes );
$self->xml_start_tag_unencoded( 'row', @attributes );
}
}
Expand Down Expand Up @@ -7135,7 +7135,7 @@ sub _write_hyperlink_external {
push @attributes, ( 'location' => $location ) if defined $location;
push @attributes, ( 'tooltip' => $tooltip ) if defined $tooltip;
$self->xml_encoded_empty_tag( 'hyperlink', @attributes );
$self->xml_empty_tag( 'hyperlink', @attributes );
}
Expand All @@ -7161,7 +7161,7 @@ sub _write_hyperlink_internal {
push @attributes, ( 'tooltip' => $tooltip ) if defined $tooltip;
push @attributes, ( 'display' => $display );
$self->xml_encoded_empty_tag( 'hyperlink', @attributes );
$self->xml_empty_tag( 'hyperlink', @attributes );
}
Expand Down Expand Up @@ -8732,7 +8732,7 @@ sub _write_ext_sparklines {
$self->_write_color_low( $sparkline->{_low_color} );
if ( $sparkline->{_date_axis} ) {
$self->xml_encoded_data_element( 'xm:f', $sparkline->{_date_axis} );
$self->xml_data_element( 'xm:f', $sparkline->{_date_axis} );
}
$self->_write_sparklines( $sparkline );
Expand Down Expand Up @@ -8766,8 +8766,8 @@ sub _write_sparklines {
my $location = $sparkline->{_locations}->[$i];
$self->xml_start_tag( 'x14:sparkline' );
$self->xml_encoded_data_element( 'xm:f', $range );
$self->xml_encoded_data_element( 'xm:sqref', $location );
$self->xml_data_element( 'xm:f', $range );
$self->xml_data_element( 'xm:sqref', $location );
$self->xml_end_tag( 'x14:sparkline' );
}
Expand Down

0 comments on commit e52a838

Please sign in to comment.