Skip to content

Commit

Permalink
Fix non-integer arguments to getline_all (issue 39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tux committed Sep 12, 2022
1 parent a31e37f commit 9d094d2
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CSV_XS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,8 @@ X<getline_all>
This will return a reference to a list of L<getline ($fh)|/getline> results.
In this call, C<keep_meta_info> is disabled. If C<$offset> is negative, as
with C<splice>, only the last C<abs ($offset)> records of C<$fh> are taken
into consideration.
into consideration. Parameters C<$offset> and C<$length> are expected to be
an integers. Non-integer values are interpreted as integer without check.
Given a CSV file with 10 lines:
Expand Down
4 changes: 2 additions & 2 deletions CSV_XS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,14 +2195,14 @@ static SV *cx_xsParse_all (pTHX_ SV *self, HV *hv, SV *io, SV *off, SV *len) {

SetupCsv (&csv, hv, self);

if (SvIOK (off)) {
if (SvOK (off)) {
skip = SvIV (off);
if (skip < 0) {
tail = -skip;
skip = -1;
}
}
if (SvIOK (len))
if (SvOK (len))
length = SvIV (len);

while (c_xsParse (csv, hv, row, NULL, io, 1)) {
Expand Down
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.49 - 2022-06-21, H.Merijn Brand
1.49 - 2022-09-12, H.Merijn Brand
* csv2xlsx --split=CxP [--split-label=C]
* Full documentation/manual for csv2xlsx
* Fix non-integer arguments to getline_all (issue 39)

1.48 - 2022-05-24, H.Merijn Brand
* It's 2022
Expand Down
5 changes: 3 additions & 2 deletions doc/CSV_XS.3
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "STDIN 1"
.TH STDIN 1 "2022-06-21" "perl v5.36.0" "User Contributed Perl Documentation"
.TH STDIN 1 "2022-09-12" "perl v5.36.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -1342,7 +1342,8 @@ The \*(L"string\*(R", \*(L"fields\*(R", and \*(L"status\*(R" methods are meaning
This will return a reference to a list of getline ($fh) results.
In this call, \f(CW\*(C`keep_meta_info\*(C'\fR is disabled. If \f(CW$offset\fR is negative, as
with \f(CW\*(C`splice\*(C'\fR, only the last \f(CW\*(C`abs ($offset)\*(C'\fR records of \f(CW$fh\fR are taken
into consideration.
into consideration. Parameters \f(CW$offset\fR and \f(CW$length\fR are expected to be
an integers. Non-integer values are interpreted as integer without check.
.PP
Given a \s-1CSV\s0 file with 10 lines:
.PP
Expand Down
2 changes: 1 addition & 1 deletion doc/CSV_XS.html
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ <h2 id="getline_all">getline_all </h2>
$arrayref = $csv-&gt;getline_all ($fh, $offset);
$arrayref = $csv-&gt;getline_all ($fh, $offset, $length);</code></pre>

<p>This will return a reference to a list of <a href="#getline">getline ($fh)</a> results. In this call, <code>keep_meta_info</code> is disabled. If <code>$offset</code> is negative, as with <code>splice</code>, only the last <code>abs ($offset)</code> records of <code>$fh</code> are taken into consideration.</p>
<p>This will return a reference to a list of <a href="#getline">getline ($fh)</a> results. In this call, <code>keep_meta_info</code> is disabled. If <code>$offset</code> is negative, as with <code>splice</code>, only the last <code>abs ($offset)</code> records of <code>$fh</code> are taken into consideration. Parameters <code>$offset</code> and <code>$length</code> are expected to be an integers. Non-integer values are interpreted as integer without check.</p>

<p>Given a CSV file with 10 lines:</p>

Expand Down
6 changes: 4 additions & 2 deletions doc/CSV_XS.man
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,9 @@ STDIN(1) User Contributed Perl Documentation STDIN(1)
This will return a reference to a list of getline ($fh) results. In
this call, "keep_meta_info" is disabled. If $offset is negative, as
with "splice", only the last "abs ($offset)" records of $fh are taken
into consideration.
into consideration. Parameters $offset and $length are expected to be
an integers. Non-integer values are interpreted as integer without
check.

Given a CSV file with 10 lines:

Expand Down Expand Up @@ -3106,4 +3108,4 @@ STDIN(1) User Contributed Perl Documentation STDIN(1)



perl v5.36.0 2022-06-21 STDIN(1)
perl v5.36.0 2022-09-12 STDIN(1)
3 changes: 2 additions & 1 deletion doc/CSV_XS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ The ["string"](#string), ["fields"](#fields), and ["status"](#status) methods ar
This will return a reference to a list of [getline ($fh)](#getline) results.
In this call, `keep_meta_info` is disabled. If `$offset` is negative, as
with `splice`, only the last `abs ($offset)` records of `$fh` are taken
into consideration.
into consideration. Parameters `$offset` and `$length` are expected to be
an integers. Non-integer values are interpreted as integer without check.

Given a CSV file with 10 lines:

Expand Down
2 changes: 1 addition & 1 deletion doc/csv2xlsx.3
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "STDIN 1"
.TH STDIN 1 "2022-06-21" "perl v5.36.0" "User Contributed Perl Documentation"
.TH STDIN 1 "2022-06-22" "perl v5.36.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down
10 changes: 5 additions & 5 deletions doc/csv2xlsx.man
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ STDIN(1) User Contributed Perl Documentation STDIN(1)

-S CxP
--split=CxP
When dealing with big CSV datasets, this option enables you to
split the data over several sheets. When all the "-S" options match
in a single row, that row will be the first row of a new sheet. (see
also "--sl=C")
When dealing with big CSV datasets, this option enables you to split
the data over several sheets. When all the "-S" options match in a
single row, that row will be the first row of a new sheet. (see also
"--sl=C")

C The column that should be examined. "A" = 1. If lower case, the
value of that column is matched case insensitive when appropriate.
Expand Down Expand Up @@ -207,4 +207,4 @@ STDIN(1) User Contributed Perl Documentation STDIN(1)



perl v5.36.0 2022-06-21 STDIN(1)
perl v5.36.0 2022-06-22 STDIN(1)
20 changes: 13 additions & 7 deletions t/77_getall.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings;

use Test::More tests => 61;
use Test::More tests => 81;

BEGIN {
require_ok "Text::CSV_XS";
Expand All @@ -28,13 +28,19 @@ sub do_tests {
$sub->(\@list);
$sub->(\@list, 0);
$sub->([@list[2,3]], 2);
$sub->([], 0, 0);
$sub->(\@list, 0, 10);
$sub->([@list[0,1]], 0, 2);
$sub->([@list[1,2]], 1, 2);
$sub->([], 0, 0);
$sub->(\@list, 0, 10);
$sub->([@list[0,1]], 0, 2);
$sub->([@list[1,2]], 1, 2);
$sub->([@list[1,2]], 1e0, 2);
$sub->([@list[1,2]], "1", 2);
$sub->([@list[1..3]], -3);
$sub->([@list[1,2]], -3, 2);
$sub->([@list[1..3]], -3, 3);
$sub->([@list[1,2]], -3, 2);
$sub->([@list[1..3]], -3, 3);

$sub->([$list[0]], 0, 1);
$sub->([$list[0]], 0, 1e0);
$sub->([$list[0]], 0, "1");
} # do_tests

foreach my $eol ("\n", "\r") {
Expand Down

0 comments on commit 9d094d2

Please sign in to comment.