Skip to content

test: add envfile parser coverage#3015

Open
abhay-dev2901 wants to merge 2 commits intoappwrite:mainfrom
abhay-dev2901:test-envfile-parser
Open

test: add envfile parser coverage#3015
abhay-dev2901 wants to merge 2 commits intoappwrite:mainfrom
abhay-dev2901:test-envfile-parser

Conversation

@abhay-dev2901
Copy link
Copy Markdown
Contributor

What does this PR do?

Adds unit test coverage for the .env parser helper used by environment variable import flows.

The tests cover parsing with = and : separators, whitespace trimming, quoted values, values containing separators, ignored
malformed/comment lines, and empty values.

Test Plan

Ran the targeted test file:

bun vitest run src/lib/helpers/envfile.test.ts

Ran the full unit test suite:

bun run test:unit

Both passed.

Related PRs and Issues

N/A

Have you read the Contributing Guidelines on issues?(https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md)

Yes.

@abhay-dev2901
Copy link
Copy Markdown
Contributor Author

@HarshMN2345 Needed your review here !

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 2, 2026

Greptile Summary

This PR adds 9 unit tests for src/lib/helpers/envfile.ts and simultaneously fixes a bug where .replace(/['"]+/g, '') was stripping every quote character anywhere in a value (e.g. O'BrienOBrien). The fix replaces it with an anchored backreference regex (/^(['"])(.*)\1$/) that only removes a matching surrounding quote pair. All previously-flagged gaps (CRLF line endings, mid-value quotes) are now covered by the new test suite.

Confidence Score: 5/5

Safe to merge — the implementation fix is correct and all tests accurately reflect the new behaviour.

No P0 or P1 issues found. The regex change is logically sound, the test expectations are correct against the updated implementation, and the CRLF case is handled correctly because trim() strips the trailing
from values before the regex is applied.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/helpers/envfile.ts Bug fix: replaces destructive global quote-stripping regex with an anchored regex that only removes surrounding matched quote pairs, preserving embedded quotes like apostrophes.
src/lib/helpers/envfile.test.ts New test file with 9 cases covering =/: separators, whitespace trimming, surrounding quotes, mid-value quotes, CRLF line endings, embedded separators, comments/malformed lines, and empty values.

Reviews (2): Last reviewed commit: "fix: preserve embedded quotes in envfile..." | Re-trigger Greptile

Comment thread src/lib/helpers/envfile.test.ts
Comment thread src/lib/helpers/envfile.test.ts
@abhay-dev2901
Copy link
Copy Markdown
Contributor Author

Fixes #3018

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

Successfully merging this pull request may close these issues.

1 participant