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

Escape stirngs passed to test-var-query #1405

Merged
merged 2 commits into from
Dec 1, 2021

Conversation

marcomorain
Copy link
Contributor

@marcomorain marcomorain commented Nov 30, 2021

What has Changed?

Per clojure-emacs/cider-nrepl#730, clients
should make sure that queries are escaped. We can use the
escape-string-regexp package, which is already in the source-tree for
this.

Also, change the call to test-var-query to narrow the search to just
test? true, and remove search-property, since name is the default
per the Cider docs.

Fixes #1383

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Added to or updated docs in this branch, if appropriate
  • Tested the VSIX built from the PR (so, after you've submitted the PR). You'll find the artifacts by clicking Show all checks in the CI section of the PR page, and then Details on the ci/circleci: build test. NB: You need to sign in/up at Circle CI to find the Artifacts tab.
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
    • Smoke tested the extension as such.
  • Referenced the issue I am fixing/addressing in a commit message for the pull request.
    • If I am fixing the issue, I have used GitHub's fixes/closes syntax
    • If I am fixing just part of the issue, I have just referenced it w/o any of the "fixes” keywords.
  • Created the issue I am fixing/addressing, if it was not present.

Ping @PEZ, @bpringe

@bpringe
Copy link
Member

bpringe commented Dec 1, 2021

Thanks! I tested the vsix using tests from #1383 and it works fine now. I think this is good to go once you update the changelog.

@PEZ
Copy link
Collaborator

PEZ commented Dec 1, 2021

The fixes look good to me too. The only thing I wonder is if there might be differences between Java and JS regexes that come into play, but I would think that we are pretty safe using JS regex escaping.

Please update the Changelog under Unreleased, @marcomorain , and we'll merge this. (Just make sure not to leave a newline between the header and the list item, we have some picky regexes in the CI scripts.)

@marcomorain
Copy link
Contributor Author

👍 Changelog updated

@PEZ
Copy link
Collaborator

PEZ commented Dec 1, 2021

We can avoid a dependency by merely doing:

string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping

WDYT?

@PEZ
Copy link
Collaborator

PEZ commented Dec 1, 2021

We have a pretty fat utilities.ts file where that can go. 😄

Per clojure-emacs/cider-nrepl#730, clients
should make sure that queries are escaped. Added a function to
utilities.ts to do this.

Also, change the call to `test-var-query` to narrow the search to just
`test?` true, and remove `search-property`, since `name` is the default
per the Cider docs.

Fixes BetterThanTomorrow#1383
@marcomorain
Copy link
Contributor Author

Updated to remove the dependency.

@PEZ PEZ merged commit e8317a8 into BetterThanTomorrow:dev Dec 1, 2021
@PEZ
Copy link
Collaborator

PEZ commented Dec 1, 2021

Awesome, such a quality improvement! Thanks! ❤️

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.

3 participants