Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#964): Allow "." in variable names + make error message more consistent #971

Merged
merged 3 commits into from Dec 1, 2023

Conversation

nelup20
Copy link
Contributor

@nelup20 nelup20 commented Nov 15, 2023

Closes #964

Thanks for creating this project btw! I was getting really disappointed with the alternatives (Insomnia, Postman, etc.) before stumbling upon Bruno on HN, and it's exactly what I was looking for.

Before After
image image
image image
image

Description

Added . to the Regex, removed the now unnecessary check with the old regex & changed the error messages to be a bit more consistent.

Also added literal-segment notation with [] around the var name when interpolating since Handlebars doesn't allow .

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

@nelup20 nelup20 marked this pull request as draft November 15, 2023 16:10
@nelup20 nelup20 marked this pull request as ready for review November 15, 2023 20:47
@nelup20
Copy link
Contributor Author

nelup20 commented Nov 23, 2023

Hi @helloanoop 👋, when I opened this PR I tested everything manually and everything seemed alright, but I had some questions about the e2e & unit tests:

  • Do the playwright tests fail at the moment for everyone on the main branch? Or is it just for me? I suspected it's a local issue just on my side, but if not I was thinking of fixing them in a new PR. (Update: pipeline failed in my fork on main, so I could have a look soon😀)
  • I was thinking of adding more unit tests in a separate PR to the bruno-electron package, maybe also to bruno-js. What do you think? Is there a specific test coverage % we'd like to reach?

@@ -1 +1 @@
export const envVariableNameRegex = /^(?!\d)[\w-]*$/;
export const envVariableNameRegex = /^(?!\d)[\w-.]*$/;
Copy link

Choose a reason for hiding this comment

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

I believe . needs to be escaped in order to be considered a literal ., otherwise, . refers to any character.

Copy link
Contributor Author

@nelup20 nelup20 Nov 29, 2023

Choose a reason for hiding this comment

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

Within a character set/class ([]) the . is treated as a literal instead of the usual "match any character" 👍

(side note: I used both https://regexr.com/ & https://regex101.com/ while testing, and the former showed no issues with this regex, but the latter displayed an error for the - which can be solved by escaping it. Not sure why there's a difference between them since they should both use the browser's JS regex engine)

@@ -1,7 +1,7 @@
const Handlebars = require('handlebars');
const { cloneDeep } = require('lodash');

const envVariableNameRegex = /^(?!\d)[\w-]*$/;
const envVariableNameRegex = /^(?!\d)[\w-.]*$/;
Copy link

Choose a reason for hiding this comment

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

Why don't we import this from packages/bruno-app/src/utils/common/regex.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, I agree and I'd also prefer to import it from one place instead of duplicating it. I wasn't sure whether to refactor it in this PR or a separate PR (not sure how it would be preferred in this project).

In this specific case, the bruno-app package is the standalone Next.js app, whereas the bruno-js package is a library used by the other packages in the codebase, so I think we can export the regex from bruno-js (or maybe another common/util package).

Copy link
Contributor Author

@nelup20 nelup20 Nov 29, 2023

Choose a reason for hiding this comment

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

I'm thinking of refactoring after all, otherwise I'll create a separate PR to keep this one small/focused
@helloanoop what do you think?

@helloanoop helloanoop merged commit 2aa876e into usebruno:main Dec 1, 2023
2 checks passed
@nelup20 nelup20 deleted the bugfix/964-env_var_dot_validation branch December 1, 2023 22:42
nelup20 added a commit to nelup20/bruno that referenced this pull request Dec 5, 2023
…n in string only to variables that are not process env vars
nelup20 added a commit to nelup20/bruno that referenced this pull request Dec 5, 2023
nelup20 added a commit to nelup20/bruno that referenced this pull request Jan 20, 2024
helloanoop pushed a commit that referenced this pull request Jan 25, 2024
…n variables + Add to CLI (#1154)

* fix(#1143): Fix PR #971 - Add literal-segment notation in string only to variables that are not process env vars
* fix(#1143): Fix PR #971 - Add to CLI as well
* fix(#1143): Fix PR #971 - Use improved Regex after CR + add test case for escaped vars
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.

Can't create environment variable with a "." in the name (Postman import issue)
3 participants