-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Expected Behavior
Should parse the diff without any errors or handle the errors gracefully.
Current Behavior
Throws an error when the diff is incorrect
Possible Solution
Check if the string is defined before accessing the .slice method.
Steps to Reproduce
- Pass the following diff to
gitDiffParser.parsemethod
'diff --git \nindex 9c96b34..853bddf 100644\n---@@ -1,8 +1,19 @@\n-// write your code here!\n const solution = () => {\n- // global clear all timeout:\n+ const allT = [];\n+ const old = setTimeout;\n+ window.setTimeout = (func, delay) => {\n+ const realTimeout = old(func, delay);\n+ allT.push(realTimeout);\n+ return realTimeout;\n+ };\n+ window.clearAllTimouts = () => {\n+ while (allT.length) {\n+ clearTimeout(allT.pop());\n+ }\n+ };\n cat = () => {\n- }\n+ window.clearAllTimouts();\n+ };\n };\n \n module.exports = solution;'It will throw:
TypeError: Cannot read properties of undefined (reading 'slice')
at parsePathFromFirstLine (node_modules/gitdiff-parser/index.js:21:35)
Context
It started happening after upgrading our app package to version 0.3.1 and I believe the issue started happening after this commit has been merged. The lines causing the error are highlighted.
Metadata
Metadata
Assignees
Labels
No labels