Skip to content

Commit 1a498bf

Browse files
authored
Fix import with malformed inline styles (#6539)
1 parent 0ac498c commit 1a498bf

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/core/src/parser/model/ParserHtml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo
7575

7676
while (str.indexOf('/*') >= 0) {
7777
const start = str.indexOf('/*');
78-
const end = str.indexOf('*/') + 2;
79-
str = str.replace(str.slice(start, end), '');
78+
const end = str.indexOf('*/');
79+
const endIndex = end > -1 ? end + 2 : undefined;
80+
str = str.replace(str.slice(start, endIndex), '');
8081
}
8182

8283
const decls = str.split(';');

packages/core/test/specs/parser/model/ParserHtml.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,17 @@ describe('ParserHtml', () => {
8484
});
8585

8686
test('Parse style with comments', () => {
87-
expect(obj.parseStyle('/* color #ffffff; */ width: 100px;')).toEqual({
87+
expect(obj.parseStyle('/* color #ffffff; */ width: 100px; /* height: 10px; */')).toEqual({
8888
width: '100px',
8989
});
9090
});
9191

92+
test('Parse style with broken comments', () => {
93+
expect(obj.parseStyle('/* color #ffffff; */ height: 50px; /* width: 10px; ')).toEqual({
94+
height: '50px',
95+
});
96+
});
97+
9298
test('Parse class string to array', () => {
9399
const str = 'test1 test2 test3 test-4';
94100
const result = ['test1', 'test2', 'test3', 'test-4'];
@@ -922,8 +928,8 @@ describe('ParserHtml', () => {
922928

923929
test('converts data-gjs-data-resolver to dataResolver', () => {
924930
const str = `
925-
<div
926-
data-gjs-type="data-variable"
931+
<div
932+
data-gjs-type="data-variable"
927933
data-gjs-data-resolver='{"type":"data-variable","path":"some path","collectionId":"someCollectionId"}'
928934
></div>
929935
`;

0 commit comments

Comments
 (0)