From 906ac25221ac8b7bdfbcd91f75d2557c0aa985dd Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 29 Apr 2022 22:05:25 -0500 Subject: [PATCH] autocomplete: fix metatags not completing until a character is typed. Fix metatags not showing autocomplete results until after the first letter was typed. For example, typing `filetype:` didn't show any completions until another letter was typed. Now typing `filetype:` shows all available file types. This was because `filetype:` by itself wasn't recognized as a valid search before, since metatags always required a value. Now it is a valid search, so it's technically possible to search for `filetype:` by itself. In this case the metatag value will be the empty string, which will return no results because there are no posts where the filetype is the empty string. This sounds nonsensical, but it's potentially useful for metatags like the `source:` metatag, where searching for posts with an empty source does make sense. It was also technically possible before by searching for `source:""`, so making the value optional doesn't change anything. --- app/logical/post_query/parser.rb | 2 +- test/unit/post_query_builder_test.rb | 1 + test/unit/post_query_parser_test.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/logical/post_query/parser.rb b/app/logical/post_query/parser.rb index 165a9ba37..2068f8724 100644 --- a/app/logical/post_query/parser.rb +++ b/app/logical/post_query/parser.rb @@ -172,7 +172,7 @@ class PostQuery expect("'") [true, a] else - [false, string(/[^ ]+/)] + [false, string(/[^ ]*/)] end end diff --git a/test/unit/post_query_builder_test.rb b/test/unit/post_query_builder_test.rb index e5327a92b..ef78ac6a6 100644 --- a/test/unit/post_query_builder_test.rb +++ b/test/unit/post_query_builder_test.rb @@ -896,6 +896,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase assert_tag_match([post3], "source:NONE") assert_tag_match([post3], 'source:""') assert_tag_match([post3], "source:''") + assert_tag_match([post3], "source:") assert_tag_match([post2, post1], "-source:none") assert_tag_match([post2, post1], "-source:''") assert_tag_match([post2, post1], '-source:""') diff --git a/test/unit/post_query_parser_test.rb b/test/unit/post_query_parser_test.rb index 72a325c38..92f5d599f 100644 --- a/test/unit/post_query_parser_test.rb +++ b/test/unit/post_query_parser_test.rb @@ -114,6 +114,7 @@ class PostQueryParserTest < ActiveSupport::TestCase assert_parse_equals('source:"foo bar"', 'source:"foo bar"') assert_parse_equals('source:foobar"(', 'source:foobar"(') + assert_parse_equals('source:', 'source:') assert_parse_equals('source:""', 'source:""') assert_parse_equals('source:"\""', 'source:"\""') assert_parse_equals(%q{source:"don't say \"lazy\" okay"}, %q{source:"don't say \"lazy\" okay"})