From 2ad99c9532f8f4548a5426a55f34b09a078f6254 Mon Sep 17 00:00:00 2001 From: Henry Heino Date: Fri, 27 Sep 2024 12:09:34 -0700 Subject: [PATCH] Mobile,Desktop: Fixes #11135: Fix incorrect numbered list regex --- .../markdown/markdownCommands.toggleList.test.ts | 15 +++++++++++++++ .../CodeMirror/markdown/markdownCommands.ts | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/editor/CodeMirror/markdown/markdownCommands.toggleList.test.ts b/packages/editor/CodeMirror/markdown/markdownCommands.toggleList.test.ts index c96bcfd59be..a8e57bd90a0 100644 --- a/packages/editor/CodeMirror/markdown/markdownCommands.toggleList.test.ts +++ b/packages/editor/CodeMirror/markdown/markdownCommands.toggleList.test.ts @@ -232,4 +232,19 @@ describe('markdownCommands.toggleList', () => { ); expect(editor.state.selection.main.from).toBe(preSubListText.length); }); + + it('should not treat a list of IP addresses as a numbered list', async () => { + const initialDocText = '192.168.1.1. This\n127.0.0.1. is\n0.0.0.0. a list'; + + const editor = await createTestEditor( + initialDocText, + EditorSelection.range(0, initialDocText.length), + [], + ); + + toggleList(ListType.UnorderedList)(editor); + expect(editor.state.doc.toString()).toBe( + '- 192.168.1.1. This\n- 127.0.0.1. is\n- 0.0.0.0. a list', + ); + }); }); diff --git a/packages/editor/CodeMirror/markdown/markdownCommands.ts b/packages/editor/CodeMirror/markdown/markdownCommands.ts index 490a8faf123..a230d50c32d 100644 --- a/packages/editor/CodeMirror/markdown/markdownCommands.ts +++ b/packages/editor/CodeMirror/markdown/markdownCommands.ts @@ -132,9 +132,9 @@ export const toggleList = (listType: ListType): Command => { // RegExps for different list types. The regular expressions MUST // be mutually exclusive. // `(?!\[[ xX]+\])` means "not followed by [x] or [ ]". - const bulletedRegex = /^\s*([-*])\s(?!\[[ xX]+\])/; - const checklistRegex = /^\s*[-*]\s\[[ xX]+\]\s?/; - const numberedRegex = /^\s*\d+\.\s?/; + const bulletedRegex = /^\s*([-*])\s(?!\[[ xX]+\]\s)/; + const checklistRegex = /^\s*[-*]\s\[[ xX]+\]\s/; + const numberedRegex = /^\s*\d+\.\s/; const listRegexes: Record = { [ListType.OrderedList]: numberedRegex,