Skip to content

Commit ab3a708

Browse files
committed
fix: accept trailing newlines in caption files
1 parent 4ba8fb0 commit ab3a708

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎telegram-client.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ class TelegramClient {
12551255
const parseMode = normalizeParseMode(options.parseMode);
12561256
if (options.expectedText !== undefined) {
12571257
const expected = applyParseMode(options.expectedText, parseMode);
1258-
const expectedPlain = typeof expected === 'string' ? expected : expected.text;
1258+
const expectedPlain = (typeof expected === 'string' ? expected : expected.text).trimEnd();
12591259
if (current.text !== expectedPlain) {
12601260
throw new Error('Current caption differs from --expected-text-file; no edit was made.');
12611261
}
@@ -1264,7 +1264,7 @@ class TelegramClient {
12641264
throw new Error('Caption cannot be empty.');
12651265
}
12661266
const parsed = applyParseMode(caption, parseMode);
1267-
const plain = typeof parsed === 'string' ? parsed : parsed.text;
1267+
const plain = (typeof parsed === 'string' ? parsed : parsed.text).trimEnd();
12681268
if (plain.length > 1024) {
12691269
throw new Error('Photo caption exceeds 1024 characters.');
12701270
}

‎tests/send-messages.test.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ describe('editPhotoCaption', () => {
166166
.mockResolvedValueOnce({ id: 77, text: 'old', media: { type: 'photo' } })
167167
.mockResolvedValueOnce({ id: 77, text: 'new', media: { type: 'photo' }, urls: ['https://example.com'] });
168168

169-
const result = await tc.editPhotoCaption('@channel', 77, 'new', {
170-
parseMode: 'markdown', expectedText: 'old',
169+
const result = await tc.editPhotoCaption('@channel', 77, 'new\n', {
170+
parseMode: 'markdown', expectedText: 'old\n',
171171
});
172172

173173
expect(tc.client.editMessage).toHaveBeenCalledWith({
174174
chatId: '@channel', message: 77,
175-
text: { text: 'new', entities: [{ type: 'bold' }] },
175+
text: { text: 'new\n', entities: [{ type: 'bold' }] },
176176
});
177177
expect(result).toEqual({ messageId: 77, media: { type: 'photo' }, urls: ['https://example.com'] });
178178
});

0 commit comments

Comments
 (0)