summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/binary.n22
-rw-r--r--generic/tclBinary.c35
-rw-r--r--tests/binary.test12
3 files changed, 55 insertions, 14 deletions
diff --git a/doc/binary.n b/doc/binary.n
index 1f93c03..92a939a 100644
--- a/doc/binary.n
+++ b/doc/binary.n
@@ -110,23 +110,27 @@ produce files that other implementations of decoders cannot process):
.TP
\fB\-maxlen \fIlength\fR
.
-Indicates that the output should be split into lines of no more than
-\fIlength\fR characters. By default, lines are split every 61 characters, and
-this must be in the range 3 to 85 due to limitations in the encoding.
+Indicates the maximum number of characters to produce for each encoded line.
+The valid range is 5 to 85. Line lengths outside that range cannot be
+accommodated by the encoding format. The default value is 61.
.TP
\fB\-wrapchar \fIcharacter\fR
.
-Indicates that, when lines are split because of the \fB\-maxlen\fR option,
-\fIcharacter\fR should be used to separate lines. By default, this is a
-newline character,
-.QW \en .
+Indicates the character(s) to use to mark the end of each encoded line.
+Acceptable values are a sequence of zero or more characters from the
+set { \\x09 (TAB), \\x0B (VT), \\x0C (FF), \\x0D (CR) } followed
+by zero or one newline \\x0A (LF). Any other values are rejected because
+they would generate encoded text that could not be decoded. The default value
+is a single newline.
.PP
During decoding, the following options are supported:
.TP
\fB\-strict\fR
.
-Instructs the decoder to throw an error if it encounters unexpected
-whitespace characters. Otherwise it ignores them.
+Instructs the decoder to throw an error if it encounters anything
+outside of the standard encoding format. Without this option, the
+decoder tolerates some deviations, mostly to forgive reflows of lines
+between the encoder and decoder.
.PP
Note that neither the encoder nor the decoder handle the header and footer of
the uuencode format.
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index 3575bce..6306159 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -2639,16 +2639,47 @@ BinaryEncodeUu(
&lineLength) != TCL_OK) {
return TCL_ERROR;
}
- if (lineLength < 3 || lineLength > 85) {
+ if (lineLength < 5 || lineLength > 85) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"line length out of range", -1));
Tcl_SetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH", NULL);
return TCL_ERROR;
}
+ lineLength = ((lineLength - 1) & -4) + 1; /* 5, 9, 13 ... */
break;
case OPT_WRAPCHAR:
- wrapchar = Tcl_GetByteArrayFromObj(objv[i + 1], &wrapcharlen);
+ wrapchar = (const unsigned char *) TclGetStringFromObj(
+ objv[i + 1], &wrapcharlen);
+ {
+ const unsigned char *p = wrapchar;
+ int numBytes = wrapcharlen;
+
+ while (numBytes) {
+ switch (*p) {
+ case '\t':
+ case '\v':
+ case '\f':
+ case '\r':
+ p++; numBytes--;
+ continue;
+ case '\n':
+ numBytes--;
+ break;
+ default:
+ badwrap:
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "invalid wrapchar; will defeat decoding",
+ -1));
+ Tcl_SetErrorCode(interp, "TCL", "BINARY",
+ "ENCODE", "WRAPCHAR", NULL);
+ return TCL_ERROR;
+ }
+ }
+ if (numBytes) {
+ goto badwrap;
+ }
+ }
break;
}
}
diff --git a/tests/binary.test b/tests/binary.test
index 399a07c..c2c5eb4 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -2794,11 +2794,17 @@ test binary-74.10 {binary encode uuencode} -returnCodes error -body {
binary encode uuencode -foo 30 abcabcabc
} -result {bad option "-foo": must be -maxlen or -wrapchar}
test binary-74.11 {binary encode uuencode} -returnCodes error -body {
- binary encode uuencode -maxlen 1 abcabcabc
+ binary encode uuencode -maxlen 4 abcabcabc
} -result {line length out of range}
test binary-74.12 {binary encode uuencode} -body {
- binary encode uuencode -maxlen 3 -wrapchar | abcabcabc
-} -result {!80|!8@|!8P|!80|!8@|!8P|!80|!8@|!8P|}
+ binary encode uuencode -maxlen 5 -wrapchar \t abcabcabc
+} -result #86)C\t#86)C\t#86)C\t
+test binary-74.13 {binary encode uuencode} -body {
+ binary encode uuencode -maxlen 85 -wrapchar \t abcabcabc
+} -result )86)C86)C86)C\t
+test binary-74.14 {binary encode uuencode} -returnCodes error -body {
+ binary encode uuencode -maxlen 86 abcabcabc
+} -result {line length out of range}
test binary-75.1 {binary decode uuencode} -body {
binary decode uuencode