func_env: Fix line counting in FILE function for DOS (CR LF) endings.

The DOS line counting mode was looking for LF CR, when it should have
been looking for CR LF. As a result, line mode never worked properly
for files with DOS (CR LF) line endings, instead erroneously
triggering an error about the offset being negative.

This bug has been present since line mode was introduced in
commit 50d5f134c8. LF CR is not
a line ending sequence that exists in any line ending format.

Swap the order around so that DOS mode works properly.
Also clarify some of the documentation around FILE operation.

Resolves: #2164
pull/2167/head
Naveen Albert 4 weeks ago committed by github-actions[bot]
parent a596c215df
commit 48e8d5a7ac

@ -144,6 +144,9 @@
<parameter name="offset">
<para>Maybe specified as any number. If negative, <replaceable>offset</replaceable> specifies the number
of bytes back from the end of the file.</para>
<note>
<para>Line offsets begin at 0, not 1.</para>
</note>
</parameter>
<parameter name="length">
<para>If specified, will limit the length of the data read to that size. If negative,
@ -173,13 +176,13 @@
used to delimit the type of line terminators in line mode.</para>
<optionlist>
<option name="u">
<para>Unix newline format.</para>
<para>Unix newline format (LF).</para>
</option>
<option name="d">
<para>DOS newline format.</para>
<para>DOS newline format (CR LF).</para>
</option>
<option name="m">
<para>Macintosh newline format.</para>
<para>Macintosh newline format (CR).</para>
</option>
</optionlist>
</parameter>
@ -547,9 +550,9 @@ static int file_count_line(struct ast_channel *chan, const char *cmd, char *data
#define LINE_COUNTER(cptr, term, counter) \
if (*cptr == '\n' && term == FF_UNIX) { \
counter++; \
} else if (*cptr == '\n' && term == FF_DOS && dos_state == 0) { \
} else if (*cptr == '\r' && term == FF_DOS && dos_state == 0) { \
dos_state = 1; \
} else if (*cptr == '\r' && term == FF_DOS && dos_state == 1) { \
} else if (*cptr == '\n' && term == FF_DOS && dos_state == 1) { \
dos_state = 0; \
counter++; \
} else if (*cptr == '\r' && term == FF_MAC) { \

Loading…
Cancel
Save