Skip to content

Commit c51b717

Browse files
eileenaaagooohgb
andauthored
fix(dql): support IRI-ref at query start (#9667)
**Description** This PR fixes a regression in DQL lexing where queries starting with an IRI-ref (names wrapped in `< >`, e.g., `<caseNodeDel_xxx>`) would fail with an `Unexpected character: U+003C '<'` error. **Root Cause:** In v25, the state function `lexIdentifyMutationOrQuery` was introduced to distinguish between mutations and queries. However, it lacked a case for the `lsThan` (`<`) character, causing the lexer to fail when a query block started with an IRI-ref instead of a standard name or keyword. **Changes:** - Updated `lexIdentifyMutationOrQuery` in `dql/state.go` to handle the `lsThan` (`<`) case. - Ensures the lexer correctly calls `lex.IRIRef` and transitions to `lexQuery`. Fixes #9666 **Checklist** - [x] The PR title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) syntax, leading with `fix:`, `feat:`, `chore:`, `ci:`, etc. - [x] Code compiles correctly and linting (via trunk) passes locally - [x] Tests added for new functionality, or regression tests for bug fixes added as applicable --------- Co-authored-by: gooohgb <[email protected]>
1 parent a1499c6 commit c51b717

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

dql/dql_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func TestParseDQL(t *testing.T) {
8686
<name> <is> <something-else> .
8787
}
8888
}`,
89+
`{
90+
<user-query>(func: uid(0x1)) {
91+
name
92+
}
93+
}`,
8994
}
9095

9196
for _, tc := range testCases {

dql/state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ func lexIdentifyMutationOrQuery(l *lex.Lexer) lex.StateFn {
388388
// else it is a query
389389
l.Emit(itemName)
390390
return lexQuery
391+
case r == lsThan:
392+
l.Backup()
393+
return lexQuery
391394
case r == '#':
392395
return lexComment
393396
case r == lex.EOF:

dql/state_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ func TestVariablesDefault(t *testing.T) {
193193
}
194194
}
195195

196+
func TestIRIRefInIdentifyMutationOrQuery(t *testing.T) {
197+
input := `{
198+
<user-query>(func: uid(0x1)) {
199+
name
200+
}
201+
}`
202+
l := lex.Lexer{
203+
Input: input,
204+
}
205+
l.Run(lexTopLevel)
206+
it := l.NewIterator()
207+
for it.Next() {
208+
item := it.Item()
209+
require.NotEqual(t, item.Typ, lex.ItemError, "Error: %v", item.String())
210+
t.Log(item.String())
211+
}
212+
}
213+
196214
func TestIRIRef(t *testing.T) {
197215
input := `
198216
query testQuery {

0 commit comments

Comments
 (0)