logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: 9c70f3e4df2e28863b51156fdbd25e253a3a1b98
parent 2c60a9b638a00db33e6c47e8642aff2ffd0ce7a0
Author: Henry Jameson <me@hjkos.com>
Date:   Sat, 12 Jun 2021 21:49:40 +0300

fixed a bug + made a testcase out of it

Diffstat:

Msrc/components/rich_content/rich_content.jsx5++---
Mtest/unit/specs/components/rich_content.spec.js35+++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx @@ -247,12 +247,13 @@ const getLinkData = (attrs, children, index) => { export const preProcessPerLine = (html, greentext, handleLinks) => { const lastMentions = [] - let nonEmptyIndex = 0 + let nonEmptyIndex = -1 const newHtml = convertHtmlToLines(html).reverse().map((item, index, array) => { // Going over each line in reverse to detect last mentions, // keeping non-text stuff as-is if (!item.text) return item const string = item.text + nonEmptyIndex += 1 // Greentext stuff if (greentext && (string.includes('&gt;') || string.includes('&lt;'))) { @@ -260,10 +261,8 @@ export const preProcessPerLine = (html, greentext, handleLinks) => { .replace(/@\w+/gi, '') // remove mentions (even failed ones) .trim() if (cleanedString.startsWith('&gt;')) { - nonEmptyIndex += 1 return `<span class='greentext'>${string}</span>` } else if (cleanedString.startsWith('&lt;')) { - nonEmptyIndex += 1 return `<span class='cyantext'>${string}</span>` } } diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js @@ -381,4 +381,39 @@ describe('RichContent', () => { expect(wrapper.html()).to.eql(compwrap(expected)) }) + + it('One buggy example', () => { + const html = [ + 'Bruh', + 'Bruh', + [ + makeMention('foo'), + makeMention('bar'), + makeMention('baz') + ].join(''), + 'Bruh' + ].join('<br>') + const expected = [ + 'Bruh', + 'Bruh', + [ + stubMention('foo'), + stubMention('bar'), + stubMention('baz') + ].join(''), + 'Bruh' + ].join('<br>') + + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) })