Skip to content

Read the STRICT environment variable in the command-line tool - #202

Open
anubhavlal07 wants to merge 1 commit into
JoshData:mainfrom
anubhavlal07:fix/cli-strict-env
Open

anubhavlal07 wants to merge 1 commit into
JoshData:mainfrom
anubhavlal07:fix/cli-strict-env

Conversation

@anubhavlal07

Copy link
Copy Markdown

The command-line tool (python -m email_validator) says that keyword arguments to validate_email can be set with environment variables of the same name in upper case. It reads every boolean option that way except strict. So STRICT=true python -m email_validator <address> ignored the variable and never ran the strict local-part length check.

Fix: add STRICT to the list of boolean environment variables in email_validator/__main__.py. It is parsed like the other options, so false/0/no/off/empty mean off.

Tests: added test_main_strict_from_env in tests/test_main.py, which passes a 65-character local part with STRICT set and expects the "too long before the @-sign" error. It fails on main, where the address is accepted and printed as JSON, and passes with the fix. flake8 is clean. The full suite (pytest -k "not network") gives 345 passed and 1 failed: test_syntax.py::test_domain_literal, which fails the same way on unmodified main in my environment. mypy has the same 2 errors in types.py as on main.

@JoshData

Copy link
Copy Markdown
Owner

Are you using STRICT? It's probably almost never the right thing to do.

@anubhavlal07

Copy link
Copy Markdown
Author

Not personally. I noticed the command-line tool ignored the STRICT environment variable while the library honours it, so I fixed the mismatch. If you'd rather not encourage STRICT from the CLI, I'm happy to close this.

@JoshData

Copy link
Copy Markdown
Owner

Well I'd rather not waste my time on reviewing PRs that no one needs. When it becomes a regular thing it's making an impact on my ability to do meaningful work.

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.

2 participants