From 1a498bfb4c1860a804aef881693bd9b02d4f7227 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 10 Jun 2025 15:56:24 +0400 Subject: [PATCH] Fix import with malformed inline styles (#6539) --- packages/core/src/parser/model/ParserHtml.ts | 5 +++-- packages/core/test/specs/parser/model/ParserHtml.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core/src/parser/model/ParserHtml.ts b/packages/core/src/parser/model/ParserHtml.ts index 35b3d28d4..ef8eff312 100644 --- a/packages/core/src/parser/model/ParserHtml.ts +++ b/packages/core/src/parser/model/ParserHtml.ts @@ -75,8 +75,9 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo while (str.indexOf('/*') >= 0) { const start = str.indexOf('/*'); - const end = str.indexOf('*/') + 2; - str = str.replace(str.slice(start, end), ''); + const end = str.indexOf('*/'); + const endIndex = end > -1 ? end + 2 : undefined; + str = str.replace(str.slice(start, endIndex), ''); } const decls = str.split(';'); diff --git a/packages/core/test/specs/parser/model/ParserHtml.ts b/packages/core/test/specs/parser/model/ParserHtml.ts index 0f0000e4e..95ffe32ab 100644 --- a/packages/core/test/specs/parser/model/ParserHtml.ts +++ b/packages/core/test/specs/parser/model/ParserHtml.ts @@ -84,11 +84,17 @@ describe('ParserHtml', () => { }); test('Parse style with comments', () => { - expect(obj.parseStyle('/* color #ffffff; */ width: 100px;')).toEqual({ + expect(obj.parseStyle('/* color #ffffff; */ width: 100px; /* height: 10px; */')).toEqual({ width: '100px', }); }); + test('Parse style with broken comments', () => { + expect(obj.parseStyle('/* color #ffffff; */ height: 50px; /* width: 10px; ')).toEqual({ + height: '50px', + }); + }); + test('Parse class string to array', () => { const str = 'test1 test2 test3 test-4'; const result = ['test1', 'test2', 'test3', 'test-4']; @@ -922,8 +928,8 @@ describe('ParserHtml', () => { test('converts data-gjs-data-resolver to dataResolver', () => { const str = ` -
`;