Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getUniqueId = () => {
export const getRecommendTitleFromMarkdownString = markdown => {
// NOTE: We should read the title from the renderer cache because this regex matches in
// code blocks too.
const tokens = markdown.match(/#{1,6} {1,}(.*\S.*)(?:\n|$)/g)
const tokens = markdown.match(/#{1,6} {1,}(?! )(.*\S.*)(?:\n|$)/g)
if (!tokens) return ''
const headers = tokens.map(t => {
const matches = t.trim().match(/(#{1,6}) {1,}(.+)/)
Expand Down
11 changes: 11 additions & 0 deletions test/unit/specs/match-electron-accelerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,14 @@ describe('Match non-character keys', () => {
})
)
})

describe('REDoS Helpers', () => {
it('should stop in 1 second', () => {
const str = '#' + ' '.repeat(100000) + '\n1\n'
const startTime = performance.now()
getRecommendTitleFromMarkdownString(str)
const endTime = performance.now()
const timeTaken = endTime - startTime
expect(timeTaken).to.be.lessThan(1000)
})
})