Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/220 highlight null #269

Merged
merged 2 commits into from Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,15 @@ exports[`createFlexMessageText should create a text for flex message 1`] = `"計

exports[`createFlexMessageText should handle the situation without input 1`] = `""`;

exports[`createHighlightContents should handle line-bot#220 issue 1`] = `
Array [
Object {
"text": "Original text",
"type": "span",
},
]
`;

exports[`createHighlightContents should create a highlight flex message 1`] = `
Array [
Object {
Expand Down
12 changes: 12 additions & 0 deletions src/webhook/handlers/__tests__/utils.test.js
Expand Up @@ -239,6 +239,18 @@ describe('createHighlightContents', () => {
it('should handle the situation without input', () => {
expect(createHighlightContents()).toMatchSnapshot();
});

it('should handle line-bot#220 issue', () => {
expect(
createHighlightContents(
{
text: null,
hyperlinks: [],
},
'Original text'
)
).toMatchSnapshot();
});
});

describe('createReplyMessages()', () => {
Expand Down
11 changes: 11 additions & 0 deletions src/webhook/handlers/utils.js
Expand Up @@ -520,6 +520,17 @@ export function createHighlightContents(
(summaries.length ? summaries.join('\n') : undefined) ||
(titles.length ? titles.join('\n') : undefined);

// fix issue 220 (api bug)
// return original text if highlight isn't null but text and hyperlinks are null
if (!text) {
return [
{
type: 'span',
text: ellipsis(oriText, lettersLimit),
},
];
}

for (let highlightPair of text.split('</HIGHLIGHT>')) {
const highlightContent = createHighlightContent(
highlightPair.split('<HIGHLIGHT>')
Expand Down