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 escape characters inside strings #17427

Closed
wants to merge 1 commit into from
Closed

Fix escape characters inside strings #17427

wants to merge 1 commit into from

Conversation

RedCMD
Copy link

@RedCMD RedCMD commented Aug 21, 2022

Fixes #17057

Before:
image

After:
image

I am very confused as what this comment means:
"comment": "this is faster than the next begin/end rule since sub-pattern will match till end-of-line and SQL files tend to have very long lines."
I did some testing and found begin/end rules to be no slower than match
if anything, match was slightly slower due to microsoft/vscode-textmate#167

For some reason double quote strings did not support escape characters what so ever
Does SQL support escape characters inside double quote strings??

`backtick \` string`
'single quote \' string'
"double quote \" string"

should also support the double char escape sequence?

`backtick `` string`
'single quote '' string'
"double quote "" string"

@ghost
Copy link

ghost commented Aug 21, 2022

CLA assistant check
All CLA requirements met.

@Charles-Gagnon
Copy link
Contributor

Thanks for looking into this!

T-SQL escapes quotes (both ' and ") by doubling them up. The backslash escape sequence isn't valid.

So these are valid strings

SELECT 'foo''bar' -> foo'bar (escaped single quote)
SELECT 'foo"bar' -> foo"bar (double quote in single-quoted string)
SELECT '''' -> ' (escaped single quote)
SELECT "foo""bar" -> foo"bar (escaped double quote)
SELECT "foo'bar" -> foo'bar (single quote in double-quoted string)
SELECT """" -> " (escaped double quote)

Not valid

SELECT 'foo\'bar'
SELECT "foo\"bar"

(Note that there's some trickiness around double quotes where you have to use SET QUOTED_IDENTIFIER OFF to use them, but for now just assuming both types of quotes are valid is fine)

@cheenamalhotra
Copy link
Member

Closing PR due to inactivity, please feel free to re-open when you have time to address feedback.

@panchoruy
Copy link

Incorrect highlighting of escaped quotes is still an issue on the current SQL syntax highlighting that ships with VSCode.
If T-SQL is supposed to behave differently then you should just provide that as a different Language Mode - rather than incorrectly highlighting all SQL that's not T-SQL.

@deemoney-rupendra
Copy link

The issue still persists. Can you please re-open this?

@Charles-Gagnon
Copy link
Contributor

See #17057 for more discussion on this

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.

Incorrect highlighting when escaping quotes in SQL
5 participants