(body: string | null)
| 5 | const debug = d('note-utils'); |
| 6 | |
| 7 | export const updatePRBodyForNoNotes = (body: string | null) => { |
| 8 | if (!body) return ''; |
| 9 | |
| 10 | let notesBody = body; |
| 11 | if (/(?:(?:\r?\n)|^)Notes: (.+?)(?:(?:\r?\n)|$)/gi.test(notesBody)) { |
| 12 | debug('Updating existing default notes template'); |
| 13 | // Bound the lazy scan to a constant number of characters. The real GitHub |
| 14 | // template comment is well under this length, but an unbounded `[\s\S]*?` |
| 15 | // under the global flag lets an attacker-controlled body (many copies of |
| 16 | // the literal prefix with no closing `-->`) force a re-scan to end-of-string |
| 17 | // per occurrence, which is O(n^2) in the body length. Capping the span keeps |
| 18 | // each match attempt O(1) so the overall replace stays linear. |
| 19 | notesBody = notesBody.replace( |
| 20 | /<!-- Please add a one-line description[\s\S]{0,1000}?-->/gi, |
| 21 | 'none', |
| 22 | ); |
| 23 | } else { |
| 24 | debug('Adding Notes: none to PR body'); |
| 25 | notesBody += '\n\n---\n\nNotes: none'; |
| 26 | } |
| 27 | |
| 28 | return notesBody; |
| 29 | }; |
| 30 | |
| 31 | export const findNoteInPRBody = (body: string | null) => { |
| 32 | if (!body) return null; |
no outgoing calls
no test coverage detected