Skip to content

Commit 1a92fdd

Browse files
fix missing spaces for original charset
1 parent f36e444 commit 1a92fdd

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

cjs/base-ex.cjs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,13 +2055,14 @@ class Base64 extends BaseTemplate {
20552055
* BaseEx UUencode Converter.
20562056
* ------------------------
20572057
*
2058-
* This is a base64 converter. Various input can be
2059-
* converted to a base64 string or a base64 string
2058+
* This is a UUencoder/UUdecoder. Various input can be
2059+
* converted to a UUencoded string or a UUencoded string
20602060
* can be decoded into various formats.
20612061
*
20622062
* Available charsets are:
20632063
* - default
2064-
* - urlsafe
2064+
* - original
2065+
* - xx
20652066
*/
20662067
class UUencode extends BaseTemplate {
20672068

@@ -2126,7 +2127,7 @@ class UUencode extends BaseTemplate {
21262127

21272128
// repeatedly take 60 chars from the output until it is empty
21282129
for (;;) {
2129-
const lArray = outArray.splice(0, 60);
2130+
const lArray = outArray.splice(0, 60).split(/\r?\n/);
21302131

21312132
// if all chars are taken, remove eventually added pad zeros
21322133
if (!outArray.length) {
@@ -2170,7 +2171,7 @@ class UUencode extends BaseTemplate {
21702171
const format = ({ input, settings }) => {
21712172

21722173
const charset = this.charsets[settings.version];
2173-
const lines = input.trim().split("\n");
2174+
const lines = input.trim().split(/\r?\n/);
21742175
const inArray = [];
21752176

21762177
if ((/^begin/i).test(lines.at(0))) {
@@ -2187,10 +2188,17 @@ class UUencode extends BaseTemplate {
21872188

21882189
inArray.push(...lArray);
21892190

2190-
if (byteCount !== 45) {
2191+
if (byteCount !== 45) {
21912192
padChars = this.converter.padChars(lArray.length) - byteCount;
21922193
break;
21932194
}
2195+
2196+
// fix missing spaces for original charset
2197+
else if (lArray.length !== 60 && settings.version === "original") {
2198+
while (inArray.length % 60) {
2199+
inArray.push(" ");
2200+
}
2201+
}
21942202
}
21952203

21962204
return inArray.join("");
@@ -3896,6 +3904,7 @@ class BaseEx {
38963904
this.base64 = new Base64("default", outputType);
38973905
this.base64_urlsafe = new Base64("urlsafe", outputType);
38983906
this.uuencode = new UUencode("default", outputType);
3907+
this.uuencode_original = new UUencode("original", outputType);
38993908
this.xxencode = new UUencode("xx", outputType);
39003909
this.base85_adobe = new Base85("adobe", outputType);
39013910
this.base85_ascii = new Base85("ascii85", outputType);

cjs/base-ex.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/converters/uuencode.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import { BaseConverter, BaseTemplate } from "../core.js";
1212
* BaseEx UUencode Converter.
1313
* ------------------------
1414
*
15-
* This is a base64 converter. Various input can be
16-
* converted to a base64 string or a base64 string
15+
* This is a UUencoder/UUdecoder. Various input can be
16+
* converted to a UUencoded string or a UUencoded string
1717
* can be decoded into various formats.
1818
*
1919
* Available charsets are:
2020
* - default
21-
* - urlsafe
21+
* - original
22+
* - xx
2223
*/
2324
export default class UUencode extends BaseTemplate {
2425

@@ -83,7 +84,7 @@ export default class UUencode extends BaseTemplate {
8384

8485
// repeatedly take 60 chars from the output until it is empty
8586
for (;;) {
86-
const lArray = outArray.splice(0, 60)
87+
const lArray = outArray.splice(0, 60).split(/\r?\n/)
8788

8889
// if all chars are taken, remove eventually added pad zeros
8990
if (!outArray.length) {
@@ -127,7 +128,7 @@ export default class UUencode extends BaseTemplate {
127128
const format = ({ input, settings }) => {
128129

129130
const charset = this.charsets[settings.version];
130-
const lines = input.trim().split("\n");
131+
const lines = input.trim().split(/\r?\n/);
131132
const inArray = [];
132133

133134
if ((/^begin/i).test(lines.at(0))) {
@@ -144,10 +145,17 @@ export default class UUencode extends BaseTemplate {
144145

145146
inArray.push(...lArray);
146147

147-
if (byteCount !== 45) {
148+
if (byteCount !== 45) {
148149
padChars = this.converter.padChars(lArray.length) - byteCount;
149150
break;
150151
}
152+
153+
// fix missing spaces for original charset
154+
else if (lArray.length !== 60 && settings.version === "original") {
155+
while (inArray.length % 60) {
156+
inArray.push(" ");
157+
}
158+
}
151159
}
152160

153161
return inArray.join("");

0 commit comments

Comments
 (0)