Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Accessing String.slice on an undefined value #33

Open
flacial opened this issue Mar 17, 2023 · 0 comments
Open

bug: Accessing String.slice on an undefined value #33

flacial opened this issue Mar 17, 2023 · 0 comments

Comments

@flacial
Copy link

flacial commented Mar 17, 2023

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

  1. Pass the following diff to gitDiffParser.parse method
'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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant