harttle / md-padding

修复 Markdown 中的混排空格:中英文、数字、链接等。
https://harttle.land/md-padding/
57 stars 5 forks source link

When the scanning cursor is at the end of the input string, parsing should NOT stop #43

Closed obgnail closed 1 month ago

obgnail commented 1 month ago

开发者你好,发现一个边界情况 BUG。

it("testcase", () => expect(padMarkdown("- ")).toEqual(`- `))

// Expected: "- "
// Received: ""

原因是 parse 函数的 while 的判断条件提前结束,导致后续的 state === State.UnorderedListItem && c === '\n' 无法执行

while (i < str.length) {
    ...
    else if (state === State.UnorderedListItem && c === '\n') {
      resolve(new UnorderedListItem(listPrefix, popNodes()), new Blank(c))
      i++
    }
}

由于 parse 的递归实现,会放大此 BUG 的影响:

it("testcase", () => {
  const src = "- <u>123</u>\n- <u>456</u>"
  expect(padMarkdown(src, { ignorePatterns: ['<u>.+?</u>'] })).toEqual(src)
})

// Expected: "- <u>123</u>\n- <u>456</u>"
// Received: "<u>123</u><u>456</u>"
obgnail commented 1 month ago

related PR: #44

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 1.9.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: