Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export function foldLine (str, maxLen = 76) {

// ensure that the line never ends with a partial escaping
// make longer lines if needed
while (curLine.substring(-1) === '\\' && pos + curLine.length < len) {
curLine += str.charAt(pos + curLine.length);
while (curLine.endsWith('\\') && pos + curLine.length < len) {
curLine += str.charAt(pos + curLine.length + 1); // Append the next character
}

// ensure that if possible, line breaks are done at reasonable places
Expand Down
30 changes: 29 additions & 1 deletion test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import { readFile as fsReadFile } from 'node:fs';
import { fileURLToPath } from 'node:url';
import * as chai from 'chai';
import { formatCharset, parseHeader, generateHeader, foldLine, parseNPluralFromHeadersSafely } from '../src/shared.js';
import { formatCharset, parseHeader, generateHeader, foldLine, parseNPluralFromHeadersSafely, compareMsgid } from '../src/shared.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -89,6 +89,17 @@ X-Poedit-SourceCharset: UTF-8`;
expect(folded.length).to.equal(3);
});

it('should ensure that the line never ends with a partial escaping', () => {
const line = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\'aaaaa\'aaaa';
const folded = foldLine(line);

expect(line).to.equal(folded.join(''));
expect(folded).to.deep.equal([
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'",
"aaaaa'aaaa"
]);
});

it('should fold at default length', () => {
const expected = ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pretium ',
'a nunc ac fringilla. Nulla laoreet tincidunt tincidunt. Proin tristique ',
Expand Down Expand Up @@ -199,3 +210,20 @@ X-Poedit-SourceCharset: UTF-8`;
});
});
});

describe('Strings Sorting function', () => {
it('should return -1 when left msgid is less than right msgid', () => {
const result = compareMsgid({ msgid: 'a' }, { msgid: 'b' });
expect(result).to.equal(-1);
});

it('should return 1 when left msgid is greater than right msgid', () => {
const result = compareMsgid({ msgid: 'b' }, { msgid: 'a' });
expect(result).to.equal(1);
});

it('should return 0 when left msgid is equal to right msgid', () => {
const result = compareMsgid({ msgid: 'a' }, { msgid: 'a' });
expect(result).to.equal(0);
});
});