Skip to content

Commit 0185bee

Browse files
committed
Fix duplicating br tags in html
1 parent b63ec8b commit 0185bee

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/flat_layout/flat_html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class FlatHTML extends FlatQuestion {
2424
}
2525

2626
private static correctHtmlRules: [{ searchRegExp: RegExp, replaceString: string }] = [
27-
{ searchRegExp: /(<\/?br\s*?\/?\s*?>\s*){2,}/, replaceString: '<br>' }
27+
{ searchRegExp: /(<\/?br\s*?\/?\s*?>\s*){2,}/g, replaceString: '<br>' }
2828
]
2929
protected correctHtml(html: string): string {
3030
FlatHTML.correctHtmlRules.forEach((rule) => {

tests/flat_html.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ test('Check correctHtml method with multiple br tags', async () => {
8686
const htmlFlat = new FlatHTML(survey, new QuestionHtmlModel('q1'), controller);
8787
expect(htmlFlat['correctHtml']('<span>Test</span><br>')).toEqual('<span>Test</span><br>');
8888
expect(htmlFlat['correctHtml']('<span>Test</span><br><br>')).toEqual('<span>Test</span><br>');
89+
expect(htmlFlat['correctHtml']('<br><br><span>Test</span><br><br>')).toEqual('<br><span>Test</span><br>');
90+
expect(htmlFlat['correctHtml']('<br><br><span>Test</span><br><br><br><span>Test</span><br><br>')).toEqual('<br><span>Test</span><br><span>Test</span><br>');
8991
expect(htmlFlat['correctHtml']('<span>Test</span><br> <br>')).toEqual('<span>Test</span><br>');
9092
expect(htmlFlat['correctHtml']('<br><span>Test</span><br>')).toEqual('<br><span>Test</span><br>');
9193
expect(htmlFlat['correctHtml']('<br><br/>')).toEqual('<br>');

0 commit comments

Comments
 (0)