Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add a lookahead for DELETE to avoid mistaking HTTP strings for SQL #315

Merged
merged 3 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions grammars/python.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@
'name': 'string.quoted.double.block.python'
'patterns': [
{
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
'name': 'meta.embedded.sql'
'end': '(?=\\s*""")'
'patterns': [
Expand All @@ -1655,7 +1655,7 @@
]
}
{
'begin': '(")(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
'begin': '(")(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
'beginCaptures':
'1':
'name': 'punctuation.definition.string.begin.python'
Expand Down Expand Up @@ -2214,7 +2214,7 @@
'name': 'string.quoted.single.block.python'
'patterns': [
{
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
'end': '(?=\\s*\'\'\')'
'name': 'meta.embedded.sql'
'patterns': [
Expand All @@ -2226,7 +2226,7 @@
]
}
{
'begin': '(\')(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
'begin': '(\')(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
'beginCaptures':
'1':
'name': 'punctuation.definition.string.begin.python'
Expand Down
7 changes: 7 additions & 0 deletions spec/python-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,10 @@ describe "Python grammar", ->
expect(tokens[13]).toEqual value: ')', scopes: ['source.python', 'string.quoted.double.single-line.sql.python', 'meta.embedded.sql', 'punctuation.definition.section.bracket.round.end.sql']
expect(tokens[15]).toEqual value: '"', scopes: ['source.python', 'string.quoted.double.single-line.sql.python', 'punctuation.definition.string.end.python']
expect(tokens[17]).toEqual value: '%', scopes: ['source.python', 'keyword.operator.arithmetic.python']

it "recognizes DELETE as an HTTP method", ->
{tokens} = grammar.tokenizeLine('"DELETE /api/v1/endpoint"')

expect(tokens[0]).toEqual value: '"', scopes: ['source.python', 'string.quoted.double.single-line.python', 'punctuation.definition.string.begin.python']
expect(tokens[1]).toEqual value: 'DELETE /api/v1/endpoint', scopes: ['source.python', 'string.quoted.double.single-line.python']
expect(tokens[2]).toEqual value: '"', scopes: ['source.python', 'string.quoted.double.single-line.python', 'punctuation.definition.string.end.python']