Skip to content

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

@flacial

Description

@flacial

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions