Skip to content

Commit

Permalink
add last bbcode text to last unclosed node
Browse files Browse the repository at this point in the history
  • Loading branch information
TrimmingFool committed Jan 29, 2023
1 parent 7b001a4 commit c8521d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions plugins/rss/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -1336,9 +1336,8 @@ theWebUI.mapBBCodeToHTML = function (htmlText) {
}
offset = match.index + match[0].length;
}
const rootNode = nodeStack[0];
rootNode.children.push(htmlText.substring(offset, htmlText.length));
const htmlContent = nodeToElement(rootNode).innerHTML;
nodeStack[nodeStack.length-1].children.push(htmlText.substring(offset, htmlText.length));
const htmlContent = nodeToElement(nodeStack[0]).innerHTML;

// Support for some emoticons from WhatCD/Gazelle (https://github.com/WhatCD/Gazelle/tree/master/static/common/smileys)
// :code: => utf8 emoticon (https://utf8-icons.com/subset/emoticons)
Expand Down
11 changes: 10 additions & 1 deletion tests/plugins/rss/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ correctContent();
document.body.appendChild($("<div>").attr("id", "rsslayout")[0]);

describe("rss details", () => {
afterEach(() => {
beforeEach(() => {
$("#rsslayout").text("");
});

it("should handle incomplete or faulty bbcode", () => {
expect(theWebUI.mapBBCodeToHTML("[i]ABC[/i]abc[b]CDE")).toEqual(
"<i>ABC</i>abc<b>CDE</b>"
);
expect(theWebUI.mapBBCodeToHTML("[i]ABC[/i]abc[b]CDE[/c]some")).toEqual(
"<i>ABC</i>abc<b>CDE[/c]some</b>"
);
});

it("should map emoticons to html", () => {
const bbcode =
"[center ][color=red ]Important :smile::shifty:[/color][/center]";
Expand Down

0 comments on commit c8521d9

Please sign in to comment.