fixed a bug + made a testcase out of it

This commit is contained in:
Henry Jameson 2021-06-12 21:49:40 +03:00
parent 2c60a9b638
commit 9c70f3e4df
2 changed files with 37 additions and 3 deletions

View File

@ -247,12 +247,13 @@ const getLinkData = (attrs, children, index) => {
export const preProcessPerLine = (html, greentext, handleLinks) => { export const preProcessPerLine = (html, greentext, handleLinks) => {
const lastMentions = [] const lastMentions = []
let nonEmptyIndex = 0 let nonEmptyIndex = -1
const newHtml = convertHtmlToLines(html).reverse().map((item, index, array) => { const newHtml = convertHtmlToLines(html).reverse().map((item, index, array) => {
// Going over each line in reverse to detect last mentions, // Going over each line in reverse to detect last mentions,
// keeping non-text stuff as-is // keeping non-text stuff as-is
if (!item.text) return item if (!item.text) return item
const string = item.text const string = item.text
nonEmptyIndex += 1
// Greentext stuff // Greentext stuff
if (greentext && (string.includes('>') || string.includes('<'))) { if (greentext && (string.includes('>') || string.includes('<'))) {
@ -260,10 +261,8 @@ export const preProcessPerLine = (html, greentext, handleLinks) => {
.replace(/@\w+/gi, '') // remove mentions (even failed ones) .replace(/@\w+/gi, '') // remove mentions (even failed ones)
.trim() .trim()
if (cleanedString.startsWith('>')) { if (cleanedString.startsWith('>')) {
nonEmptyIndex += 1
return `<span class='greentext'>${string}</span>` return `<span class='greentext'>${string}</span>`
} else if (cleanedString.startsWith('&lt;')) { } else if (cleanedString.startsWith('&lt;')) {
nonEmptyIndex += 1
return `<span class='cyantext'>${string}</span>` return `<span class='cyantext'>${string}</span>`
} }
} }

View File

@ -381,4 +381,39 @@ describe('RichContent', () => {
expect(wrapper.html()).to.eql(compwrap(expected)) 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))
})
}) })