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

Unescaped source path in JSON body of DAP output event causes errors in nvim-dap #175

Open
tbrauredev opened this issue Sep 16, 2024 · 1 comment · May be fixed by #176
Open

Unescaped source path in JSON body of DAP output event causes errors in nvim-dap #175

tbrauredev opened this issue Sep 16, 2024 · 1 comment · May be fixed by #176
Labels

Comments

@tbrauredev
Copy link

Description

I'm trying to use netcoredbg from neovim through nvim-dap and I get the following errors when debuging a simple ASP.NET Core Web API template project on Windows:

Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 209
stack traceback:
    [C]: in function 'json_decode'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
    vim/_editor.lua:351: in function <vim/_editor.lua:350>

Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 217
stack traceback:
    [C]: in function 'json_decode'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
    vim/_editor.lua:351: in function <vim/_editor.lua:350>

Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 201
stack traceback:
    [C]: in function 'json_decode'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
    vim/_editor.lua:351: in function <vim/_editor.lua:350>

Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 212
stack traceback:
    [C]: in function 'json_decode'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
    ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
    vim/_editor.lua:351: in function <vim/_editor.lua:350>

I added a few traces in nvim-dap's session.lua and found the problematic JSON body:

{
  "seq": 111,
  "event": "output",
  "type": "event",
  "body": {
    "category": "stdout",
    "output"...r\n",
    "source": {
      "name": "Program.cs",
      "path": "C:\Dev\csharp-project\WebApi1\Program.cs"
    }
  }
}

Note the unescaped backslashes in the path of the source file. Looking at the code of netcoredgb, it seems that it could easily be fixed by wrapping source.path in an EscapedString<JSON_escape_rules> within serialize_output in src/protocol/vscodeprotocol.cpp.

I have tested this fix on my side and it works, I can submit a PR if needed.

Just for the record, here is my nvim-dap configuration:

local dap = require("dap")

dap.adapters["coreclr"] = {
  type = "executable",
  command = vim.fn.exepath("netcoredbg"),
   args = { "--interpreter=vscode" },
   options = {
     detached = false,
   },
}

dap.configurations["cs"] = {
  {
    type = "coreclr",
    name = "Debug C# App",
    request = "launch",
    program = function()
        return vim.fn.input("Path to dll", vim.fn.getcwd() .. "/bin/Debug/", "file")
    end,
  },
}

And I created my C# App using dotnet new webapi -o WebApi1.

@viewizard
Copy link
Member

I have tested this fix on my side and it works, I can submit a PR if needed.

Sure, please, submit PR, we will take a look and test it in our internal CI.

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

Successfully merging a pull request may close this issue.

2 participants