Commit Graph
13 Commits
Author SHA1 Message Date
Rohan Verma c92e518f6a tests: add unit tests for parser errors
- Declares errors and wraps them for error checking
by clients
- Adds two unit tests for
  - terminated quote error
  - unexpected char
2026-05-20 14:20:46 +10:00
John Barton 59c0ac271a Merge pull request #252 from lotusirous/main
simplify Replace(..,-1) by ReplaceAll for strings and bytes
2026-05-19 21:55:59 +10:00
John Barton 03bb54a6e3 Merge branch 'pr-245-merge-prep' 2026-05-19 16:30:42 +10:00
John Barton 529bc60899 Merge branch 'fix/escaped-backslash-quote'
fix: don't treat closing quote as escaped after an escaped backslash

The quoted-value terminator loop in extractVarValue treated any
backslash before a quote as an escape, so values ending in an even
number of backslashes (e.g. FOO="bar\\") parsed as "unterminated
quoted value". Replace the single-byte check with a walk-back that
counts the preceding backslash run — escape only when odd.

Closes #225. Does not address #226 (TrimRightFunc stripping a
legitimate escaped quote at the tail of a value) — that's a
separate bug in a different code path.
2026-05-19 15:54:54 +10:00
Sai Asish Y b724238db6 fix: don't treat closing quote as escaped after an escaped backslash 2026-05-12 21:37:38 -07:00
Yanhu007 3ec7e17a8d refactor: replace recursion with loop in getStatementStart
Convert the recursive getStatementStart function to an iterative
loop. This prevents potential stack overflow on files with a very
large number of consecutive comment lines.

Ref #232
2026-04-14 14:39:45 +08:00
Kha Nguyen 44124b6598 simplify Replace(..,-1) by ReplaceAll for strings and bytes 2025-11-09 10:44:05 +07:00
Parker Brown a2be92d182 Fix typo in hasQuotePrefix return variable (#251)
Corrected the spelling of the return variable from 'isQuored' to 'isQuoted' in the hasQuotePrefix function.
2025-10-22 10:26:18 +11:00
James Wert 82194f2733 Version 1.4.0 allowed hyphen "-" to be in environment variable names, after 1.4.0 this resulted in a parsing error which breaks backwards compatibility. Added back in hyphen support in variable names with associated test cases. 2025-03-31 09:34:30 -04:00
柚子uccs 3a7a190201 fix: if a line contains multiple # characters, there will be issues w… (#238)
* fix: if a line contains multiple # characters, there will be issues when traversing from back to front

* fix: typo
2024-12-16 15:14:19 +11:00
Andrey NovikovandStanislau Arsoba a7f6c4c583 Re-add global env variable substitution (#227)
Co-authored-by: Stanislau Arsoba <sarsoba@klika-tech.com>
2024-11-01 09:24:06 +11:00
John Barton 3fc4292b58 Fix bug where internal unquoted whitespace truncates values (#205)
* Add tests to cover the regression reported in #204

* Add a comment on regex for clarity

* Remove some old code that wasn't doing anything

* Push _all_ parse code into the parser and get tests calling live code

* Add some newline specific tests

* Add some YAML tests for the newline/space split bug

* Fix incorrect terminating of lines on whitespace

* Fix most of the parser regressions

* Bring back FOO.BAR names

* remove some commented out code
2023-02-06 08:47:38 +11:00
cc9e9b7de7 Multiline string support (#156)
* refactor dotenv parser in order to support multi-line variable values declaration

Signed-off-by: x1unix <denis0051@gmail.com>

* Add multi-line var values test case and update comment test

Signed-off-by: x1unix <denis0051@gmail.com>

* Expand fixture tests to include multiline strings

* Update go versions to test against

* Switch to GOINSECURE for power8 CI task

* When tests fail, show source version of string (inc special chars)

* Update parser.go

Co-authored-by: Austin Sasko <austintyler0239@yahoo.com>

* Fix up bad merge

* Add a full fixture for comments for extra piece of mind

* Fix up some lint/staticcheck recommendations

* Test against go 1.19 too

Signed-off-by: x1unix <denis0051@gmail.com>
Co-authored-by: x1unix <denis0051@gmail.com>
Co-authored-by: Austin Sasko <austintyler0239@yahoo.com>
2023-01-27 13:14:16 +11:00