Skip to content

fix: escape receiver texts in completion #12646

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

Merged
merged 4 commits into from
Jul 20, 2022
Merged

Conversation

lowr
Copy link
Contributor

@lowr lowr commented Jun 27, 2022

This PR fixes #11897 by escaping '\' and '$' in the text of the receiver position expression. See here for the specification of the snippet syntax (especially this section discusses escaping).

Although not all occurrences of '\' and '$' have to be replaced, I chose to replace all as that's simpler and easier to understand. There are more clever ways to implement it, but I thought they were premature optimization for the time being (maybe I should put FIXME notes?).

//
// Note that we don't need to escape the other characters that can be escaped,
// because they wouldn't be treated as snippet-specific constructs without '$'.
text.replace('\\', "\\\\").replace('$', "\\$")
Copy link
Member

Choose a reason for hiding this comment

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

According to the spec https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#grammar we also need to escape } then do we not? (I have the bad feeling we might need to be smarter about escaping, but if that is the case that can be something for another PR. This fixes the bigger problematic ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only need to escape } inside the snippet-specific construct, i.e. ${}, to disambiguate it from the ending token of the syntax. Now that we escape every occurrence of $ with this patch, we wouldn't have ${} in the first place so I believe there's no need (I've built r-a and tested the behavior, and it worked as expected at least in my local environment).

I think this was my reasoning when writing this patch, but let me know if I'm missing anything!

@Veykril
Copy link
Member

Veykril commented Jul 20, 2022

Thanks!
@bors delegate+

@bors
Copy link
Contributor

bors commented Jul 20, 2022

✌️ @lowr can now approve this pull request

@lowr
Copy link
Contributor Author

lowr commented Jul 20, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 20, 2022

📌 Commit cfc52ad has been approved by lowr

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 20, 2022

⌛ Testing commit cfc52ad with merge f3e9b38...

@bors
Copy link
Contributor

bors commented Jul 20, 2022

☀️ Test successful - checks-actions
Approved by: lowr
Pushing f3e9b38 to master...

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.

Using postfix snippets on expressions containing '\\' results in it getting unescaped
3 participants