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

Commit 2ba8196

Browse files
authored
Merge pull request #315 from illright/fix/mistaken-sql
Add a lookahead for DELETE to avoid mistaking HTTP strings for SQL
2 parents 66f35ea + 64010bf commit 2ba8196

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

grammars/python.cson

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@
16431643
'name': 'string.quoted.double.block.python'
16441644
'patterns': [
16451645
{
1646-
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
1646+
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
16471647
'name': 'meta.embedded.sql'
16481648
'end': '(?=\\s*""")'
16491649
'patterns': [
@@ -1655,7 +1655,7 @@
16551655
]
16561656
}
16571657
{
1658-
'begin': '(")(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
1658+
'begin': '(")(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
16591659
'beginCaptures':
16601660
'1':
16611661
'name': 'punctuation.definition.string.begin.python'
@@ -2214,7 +2214,7 @@
22142214
'name': 'string.quoted.single.block.python'
22152215
'patterns': [
22162216
{
2217-
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
2217+
'begin': '(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
22182218
'end': '(?=\\s*\'\'\')'
22192219
'name': 'meta.embedded.sql'
22202220
'patterns': [
@@ -2226,7 +2226,7 @@
22262226
]
22272227
}
22282228
{
2229-
'begin': '(\')(?=\\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER|WITH))'
2229+
'begin': '(\')(?=\\s*(SELECT|INSERT|UPDATE|DELETE(?! \/)|CREATE|REPLACE|ALTER|WITH))'
22302230
'beginCaptures':
22312231
'1':
22322232
'name': 'punctuation.definition.string.begin.python'

spec/python-spec.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,10 @@ describe "Python grammar", ->
750750
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']
751751
expect(tokens[15]).toEqual value: '"', scopes: ['source.python', 'string.quoted.double.single-line.sql.python', 'punctuation.definition.string.end.python']
752752
expect(tokens[17]).toEqual value: '%', scopes: ['source.python', 'keyword.operator.arithmetic.python']
753+
754+
it "recognizes DELETE as an HTTP method", ->
755+
{tokens} = grammar.tokenizeLine('"DELETE /api/v1/endpoint"')
756+
757+
expect(tokens[0]).toEqual value: '"', scopes: ['source.python', 'string.quoted.double.single-line.python', 'punctuation.definition.string.begin.python']
758+
expect(tokens[1]).toEqual value: 'DELETE /api/v1/endpoint', scopes: ['source.python', 'string.quoted.double.single-line.python']
759+
expect(tokens[2]).toEqual value: '"', scopes: ['source.python', 'string.quoted.double.single-line.python', 'punctuation.definition.string.end.python']

0 commit comments

Comments
 (0)