KEMBAR78
feat: Add check for values that require surrounding quotes by tabfugnic · Pull Request #521 · dotenv-linter/dotenv-linter · GitHub
Skip to content

Conversation

@tabfugnic
Copy link
Contributor

@tabfugnic tabfugnic commented Jun 7, 2022

When evaluating variables, values with spaces will only evaluate the first word/character before a space and ignore the rest. This is especially bad because this fails silently in most cases and can lead to confusing scenarios.

This ensures that any value that contains a space must have quotes surrounding it so that it is valid.

This does not consider any value that has a leading or trailing space since that is managed by other checks/fixes.

Further Fixes: #343

✔ Checklist:

  • Commit messages have been written in Conventional Commits format;
  • This PR has been added to CHANGELOG.md (at the top of the list);
  • Tests for the changes have been added (for bug fixes / features);
  • Docs have been added / updated on the dotenv-linter.github.io (for bug fixes / features).

Copy link
Member

@mgrachev mgrachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tabfugnic 👋
Thank you for your contribution 👍

I have left some comments. Please take a look at them 👀

@mgrachev
Copy link
Member

mgrachev commented Jun 8, 2022

@dotenv-linter/core Hey!
What do you think about the new check?
Do you have any comments/suggestions?

@codecov-commenter
Copy link

Codecov Report

Merging #521 (c282813) into master (bd224a2) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #521      +/-   ##
==========================================
+ Coverage   98.92%   98.94%   +0.02%     
==========================================
  Files          41       43       +2     
  Lines        2705     2757      +52     
==========================================
+ Hits         2676     2728      +52     
  Misses         29       29              
Impacted Files Coverage Δ
src/checks.rs 100.00% <100.00%> (ø)
src/checks/needs_quotes.rs 100.00% <100.00%> (ø)
src/common/lint_kind.rs 100.00% <100.00%> (ø)
src/fixes.rs 92.00% <100.00%> (+0.05%) ⬆️
src/fixes/needs_quotes.rs 100.00% <100.00%> (ø)
src/lib.rs 99.00% <0.00%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd224a2...c282813. Read the comment docs.

When evaluating variables, values with spaces will only evaluate the
first word/character before a space and ignore the rest. This is
especially bad because this fails silently in most cases and can lead
to confusing scenarios.

This ensures that any value that contains a space must have quotes
surrounding it so that it is valid.

This does not consider any value that has a leading or trailing space
since that is managed by other checks/fixes.

Further Fixes: dotenv-linter#343
Add line for needing quotes feature
Comment on lines +26 to +28
if val.contains(char::is_whitespace)
&& !(val.starts_with('\'') && val.ends_with('\''))
&& !(val.starts_with('\"') && val.ends_with('\"'))
Copy link
Member

@DDtKey DDtKey Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFYI: Actually there may be false-positive check results
For example, here are also valid ENV vars:

A=B' 'C # => B C
B=SOME" text will be here" # => SOME text will be here

But I think your PR cover a good issue and it's already enough to catch mistakes/guhs. For such "unusual" cases users always can use special-comments (# dotenv-linter:off ValueWithoutQuotes) 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know about that 😅

Copy link
Member

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, I vote for this PR 👍

@mgrachev mgrachev merged commit 015c82c into dotenv-linter:master Jun 17, 2022
@mgrachev
Copy link
Member

mgrachev commented Jun 17, 2022

@tabfugnic Thanks a lot 🔥

@tabfugnic tabfugnic deleted the ensure_quotes branch June 17, 2022 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Many values SHOULD be quoted

4 participants