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

Commit afcbac3

Browse files
authored
Unescaped identifiers cannot start with underscores (#22)
1 parent 488cc6e commit afcbac3

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

src/SqlSquared/Parser/Tokenizer.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ quotedIdent =
190190

191191
notQuotedIdent m. Monad m P.ParserT String m String
192192
notQuotedIdent = do
193-
first ← PT.letter <|> PS.char '_'
193+
first ← PT.letter
194194
other ← A.many (PT.alphaNum <|> PS.char '_')
195195
let
196196
str = S.fromCharArray $ A.cons first other

src/SqlSquared/Signature/Ident.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ printIdent str =
1212
then str
1313
else "`" <> Regex.replace tick "\\`" str <> "`"
1414
where
15-
identifier = Regex.unsafeRegex "^[_a-z][_a-z0-9]*$" Regex.ignoreCase
15+
identifier = Regex.unsafeRegex "^[a-z][_a-z0-9]*$" Regex.ignoreCase
1616
tick = Regex.unsafeRegex "`" Regex.global

test/src/Parse.purs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,43 @@ import Test.Unit (suite, test, TestSuite)
1010
import Test.Unit.Assert as Assert
1111
import Test.Unit.Console as Console
1212

13-
testPrintParse e. String TestSuite (testOutput Console.TESTOUTPUT | e)
14-
testPrintParse s =
15-
test s case parseQuery s of
16-
E.Left err → Assert.assert (show err) false
17-
E.Right (sql SqlQuery) → pure unit
13+
testPrintParse e. E.Either String String TestSuite (testOutput Console.TESTOUTPUT | e)
14+
testPrintParse = case _ of
15+
E.Left s → do
16+
test s case parseQuery s of
17+
E.Left err → pure unit
18+
E.Right (sql SqlQuery) → Assert.assert "Parse succeeded" false
19+
E.Right s → do
20+
test s case parseQuery s of
21+
E.Left err → Assert.assert (show err) false
22+
E.Right (sql SqlQuery) → pure unit
1823

19-
inputs Array String
24+
inputs Array (E.Either String String)
2025
inputs =
21-
[ """select a from `/f` where b is not between 1 and (2..3)"""
22-
, """select foo, bar from (select foo, bar from (select foo, bar from `/baz`)as t) as d"""
23-
, """select (1 + 2) * 3 + 2"""
24-
, """select 1 + 2 * 3 ^ 1.2 / 14 + Minimum(12, 23)"""
25-
, """select ("12" || "12" || "12")"""
26-
, """select date("12-12-12") from `/fo` cross join `/bar`"""
27-
, """Select foo as bar from `/test/db/collection`"""
28-
, """Select `foo`, `bar`[*] from `/test` join `/test2` on baz where doo = (12 + 23)"""
29-
, """foo := 12; select * from `/test` group by baz"""
30-
, """select 1"""
31-
, """select (1, 2)"""
32-
, """foo := [1, 2]; select 1"""
33-
, """foo := 1; bar := 2; select [] """
34-
, """select foo from `/bar` order by zoo desc"""
35-
, """select distinct a from `/f`"""
36-
, """select a from /* trololo */ `/db`"""
37-
, """-- comment
26+
[ E.Right """select a from `/f` where b is not between 1 and (2..3)"""
27+
, E.Right """select foo, bar from (select foo, bar from (select foo, bar from `/baz`)as t) as d"""
28+
, E.Right """select (1 + 2) * 3 + 2"""
29+
, E.Right """select 1 + 2 * 3 ^ 1.2 / 14 + Minimum(12, 23)"""
30+
, E.Right """select ("12" || "12" || "12")"""
31+
, E.Right """select date("12-12-12") from `/fo` cross join `/bar`"""
32+
, E.Right """Select foo as bar from `/test/db/collection`"""
33+
, E.Right """Select `foo`, `bar`[*] from `/test` join `/test2` on baz where doo = (12 + 23)"""
34+
, E.Right """foo := 12; select * from `/test` group by baz"""
35+
, E.Right """select 1"""
36+
, E.Right """select (1, 2)"""
37+
, E.Right """foo := [1, 2]; select 1"""
38+
, E.Right """foo := 1; bar := 2; select [] """
39+
, E.Right """select foo from `/bar` order by zoo desc"""
40+
, E.Right """select distinct a from `/f`"""
41+
, E.Right """select a from /* trololo */ `/db`"""
42+
, E.Right """-- comment
3843
select 12
3944
"""
40-
, """import foo; select * from `/test`"""
41-
, """create function foo(:bar) begin :bar + 2 end; select * from `/test` where foo = foo(42)"""
42-
, """select :where"""
45+
, E.Right """import foo; select * from `/test`"""
46+
, E.Right """create function foo(:bar) begin :bar + 2 end; select * from `/test` where foo = foo(42)"""
47+
, E.Right """select :where"""
48+
, E.Right """foo.`_id`"""
49+
, E.Left """foo._id"""
4350
]
4451

4552
testSuite e. TestSuite (testOutput Console.TESTOUTPUT | e)

0 commit comments

Comments
 (0)