diff --git a/src/static/js/contentcollector.ts b/src/static/js/contentcollector.ts
index 5b9d7f362..a2140d6fd 100644
--- a/src/static/js/contentcollector.ts
+++ b/src/static/js/contentcollector.ts
@@ -504,9 +504,14 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author)
// See https://github.com/ether/etherpad-lite/issues/2412 for reasoning
if (!abrowser.chrome) oldListTypeOrNull = (_enterList(state, undefined) || 'none');
} else if (tname === 'li') {
+ // If the
has no parent / (e.g., pasted bare HTML), default to bullet list.
+ // See https://github.com/ether/etherpad-lite/issues/6665
+ if (!state.lineAttributes.list) {
+ oldListTypeOrNull = (_enterList(state, 'bullet1') || 'none');
+ }
state.lineAttributes.start = state.start || 0;
_recalcAttribString(state);
- if (state.lineAttributes.list.indexOf('number') !== -1) {
+ if (state.lineAttributes.list && state.lineAttributes.list.indexOf('number') !== -1) {
/*
Nested OLs are not --> - 1
nested
They are --> - 1
- nested
diff --git a/src/tests/backend/specs/contentcollector.ts b/src/tests/backend/specs/contentcollector.ts
index 50178fbae..f7b7a3adf 100644
--- a/src/tests/backend/specs/contentcollector.ts
+++ b/src/tests/backend/specs/contentcollector.ts
@@ -332,6 +332,33 @@ pre
wantAlines: ['+f*1+2+2'],
wantText: ['Need more space s !'],
},
+ {
+ description: 'Bare - without parent
/ should not crash (bug #6665)',
+ html: '- this should not crash
',
+ wantAlines: [
+ '*0*2*6+1+l',
+ ],
+ wantText: ['*this should not crash'],
+ },
+ {
+ description: 'Multiple bare - elements without parent list',
+ html: '
- first
- second
',
+ wantAlines: [
+ '*0*2*6+1+5',
+ '*0*2*6+1+6',
+ ],
+ wantText: ['*first', '*second'],
+ },
+ {
+ description: 'Mixed bare - and normal content',
+ html: '
before
- bare item
after
',
+ wantAlines: [
+ '+6',
+ '*0*2*6+1+9',
+ '+5',
+ ],
+ wantText: ['before', '*bare item', 'after'],
+ },
];
describe(__filename, function () {