Detect error when a prefix of a valid node name is used in a query
This commit is contained in:
parent
c71de5bd81
commit
67dcbc3e73
3 changed files with 10 additions and 8 deletions
|
|
@ -44,12 +44,12 @@ fn test_query_errors_on_invalid_symbols() {
|
|||
let language = get_language("javascript");
|
||||
|
||||
assert_eq!(
|
||||
Query::new(language, "(non_existent1)"),
|
||||
Err(QueryError::NodeType("non_existent1"))
|
||||
Query::new(language, "(clas)"),
|
||||
Err(QueryError::NodeType("clas"))
|
||||
);
|
||||
assert_eq!(
|
||||
Query::new(language, "(if_statement (non_existent2))"),
|
||||
Err(QueryError::NodeType("non_existent2"))
|
||||
Query::new(language, "(if_statement (arrayyyyy))"),
|
||||
Err(QueryError::NodeType("arrayyyyy"))
|
||||
);
|
||||
assert_eq!(
|
||||
Query::new(language, "(if_statement condition: (non_existent3))"),
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ describe("Query", () => {
|
|||
assert.throws(() => {
|
||||
JavaScript.query("(non_existent)")
|
||||
}, "Bad node name 'non_existent'");
|
||||
assert.throws(() => {
|
||||
JavaScript.query("(a)")
|
||||
}, "Bad node name 'a'");
|
||||
assert.throws(() => {
|
||||
JavaScript.query("(function_declaration non_existent:(identifier))")
|
||||
}, "Bad field name 'non_existent'");
|
||||
|
|
|
|||
|
|
@ -237,10 +237,9 @@ static TSSymbol ts_query_intern_node_name(
|
|||
) {
|
||||
uint32_t symbol_count = ts_language_symbol_count(self->language);
|
||||
for (TSSymbol i = 0; i < symbol_count; i++) {
|
||||
if (
|
||||
ts_language_symbol_type(self->language, i) == symbol_type &&
|
||||
!strncmp(ts_language_symbol_name(self->language, i), name, length)
|
||||
) return i;
|
||||
if (ts_language_symbol_type(self->language, i) != symbol_type) continue;
|
||||
const char *symbol_name = ts_language_symbol_name(self->language, i);
|
||||
if (!strncmp(symbol_name, name, length) && !symbol_name[length]) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue