Skip to content

DotEnv parser don't allow values with # #514

@filipiz

Description

@filipiz

Prerequisites

  • I am using the latest stable release of Neovim
  • I am using the latest version of the plugin

Neovim Version

NVIM v0.11.0-dev-783+g0ade8fed1

Operating system/version

Arch Linux

Actual behavior

Dotenv parser don't let setting value that contains the # character.

var1=value#hashtag # this is a comment
var2="value#hashtag" # this is another comment
var3=thisisok # comment

results in

var1 = value
var2 = "value
var3 = thisisok

It also fails to process comments correctly.

var1=foo
# var1=bar

results in var1 = bar

Expected behavior

a dotenv file like

var1=value#hashtag # this is a comment
var2="value#hashtag" # this is another comment
var3=thisisok # comment
# var3=thisisnotok

results in

var1 = value#hastag
var2 = value#hashtag
var3 = thisisok

Steps to reproduce

  1. Create a dotenv file with comments as described.
  2. Try to use the variables

They will contain the wrong values.

Other information

I made a partial solution in this PR: #513

It is not perfect because a dotenv file like

var1=value # with comment that # contais hash

will result in

var1 = value # with comment that

But more resilient then current implementation.
Can be used until implementation with tree-sitter-bash is made.

Repro (lazy.nvim)

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        "rest-nvim/rest.nvim",
        {
            "nvim-treesitter/nvim-treesitter",
            build = ":TSUpdate",
            main = "nvim-treesitter.configs",
            opts = {
                ensure_installed = { "http" },
                sync_install = false,
                highlight = { enable = true },
                indent = { enable = true },
            },
        },
    },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions