From 11d47fed3727ce8b60c7f18ab800827ccf3ad2af Mon Sep 17 00:00:00 2001 From: Evgenii Klimov Date: Mon, 1 Jan 2024 06:11:08 +0300 Subject: [PATCH 1/2] fix(scanner): do not allow whitespaces in dollar quote tag --- src/scanner.c | 2 +- test/corpus/errors.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/scanner.c b/src/scanner.c index f950022e..de026c07 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -64,7 +64,7 @@ char* scan_dollar_string_tag(TSLexer *lexer) { return NULL; } - while (lexer->lookahead != '$' && !lexer->eof(lexer)) { + while (lexer->lookahead != '$' && !iswspace(lexer->lookahead) && !lexer->eof(lexer)) { tag = add_char(tag, text_size, lexer->lookahead, ++index); lexer->advance(lexer, false); } diff --git a/test/corpus/errors.txt b/test/corpus/errors.txt index 31f97c3e..282fd72b 100644 --- a/test/corpus/errors.txt +++ b/test/corpus/errors.txt @@ -141,3 +141,45 @@ $c$; (UNEXPECTED 'c') (UNEXPECTED ';')) (MISSING dollar_quote))))) + +================================================================================ +Function body with a tag name contains whitespace +================================================================================ + +create or replace function public.do_stuff() + returns trigger + language plpgsql +as $a $ +begin + return $b$text$b$; +end; +$a $; + +-------------------------------------------------------------------------------- + +(program + (ERROR + (keyword_create) + (keyword_or) + (keyword_replace) + (keyword_function) + (object_reference + (identifier) + (identifier)) + (function_arguments) + (keyword_returns) + (keyword_trigger) + (function_language + (keyword_language) + (identifier)) + (ERROR + (keyword_as) + (UNEXPECTED 'a') + (UNEXPECTED '\n')) + (keyword_begin) + (dollar_quote) + (keyword_text) + (dollar_quote) + (keyword_end) + (UNEXPECTED 'a') + (UNEXPECTED ';'))) From fe2dd4228bdb14fc801fa3aeb2ab778a10fa1e4c Mon Sep 17 00:00:00 2001 From: Evgenii Klimov Date: Tue, 2 Jan 2024 23:48:54 +0300 Subject: [PATCH 2/2] fix(test): avoid use of newline character --- test/corpus/errors.txt | 62 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/test/corpus/errors.txt b/test/corpus/errors.txt index 282fd72b..39b94aec 100644 --- a/test/corpus/errors.txt +++ b/test/corpus/errors.txt @@ -149,37 +149,43 @@ Function body with a tag name contains whitespace create or replace function public.do_stuff() returns trigger language plpgsql -as $a $ +as $a$ begin - return $b$text$b$; + return $b $text$b $; end; -$a $; +$a$; -------------------------------------------------------------------------------- (program - (ERROR - (keyword_create) - (keyword_or) - (keyword_replace) - (keyword_function) - (object_reference - (identifier) - (identifier)) - (function_arguments) - (keyword_returns) - (keyword_trigger) - (function_language - (keyword_language) - (identifier)) - (ERROR - (keyword_as) - (UNEXPECTED 'a') - (UNEXPECTED '\n')) - (keyword_begin) - (dollar_quote) - (keyword_text) - (dollar_quote) - (keyword_end) - (UNEXPECTED 'a') - (UNEXPECTED ';'))) + (statement + (create_function + (keyword_create) + (keyword_or) + (keyword_replace) + (keyword_function) + (object_reference + (identifier) + (identifier)) + (function_arguments) + (keyword_returns) + (keyword_trigger) + (function_language + (keyword_language) + (identifier)) + (function_body + (keyword_as) + (dollar_quote) + (keyword_begin) + (keyword_return) + (ERROR + (UNEXPECTED 'b')) + (field + (identifier)) + (ERROR + (UNEXPECTED 't') + (keyword_text) + (UNEXPECTED 'b') + (UNEXPECTED ';')) + (keyword_end) + (dollar_quote)))))