Skip to content

Commit a69f786

Browse files
committed
XWIKI-23497: Toggling search facets inserts empty space above the search form
* Remove indentation from query limit validation macros to avoid extra whitespace. * Add a page test that verifies that there isn't any empty space above the search form.
1 parent 5bc5c0d commit a69f786

File tree

2 files changed

+34
-15
lines changed
  • xwiki-platform-core
    • xwiki-platform-search/xwiki-platform-search-solr/xwiki-platform-search-solr-ui/src/test/java/org/xwiki/search/solr/ui
    • xwiki-platform-web/xwiki-platform-web-templates/src/main/resources/templates

2 files changed

+34
-15
lines changed

xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-solr/xwiki-platform-search-solr-ui/src/test/java/org/xwiki/search/solr/ui/SolrSearchPageTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.io.PrintWriter;
2323
import java.io.StringWriter;
2424

25+
import org.jsoup.nodes.Document;
26+
import org.jsoup.nodes.Element;
2527
import org.junit.jupiter.api.BeforeEach;
2628
import org.junit.jupiter.api.Test;
2729
import org.xwiki.model.reference.DocumentReference;
@@ -42,6 +44,8 @@
4244
import com.xpn.xwiki.plugin.feed.FeedPlugin;
4345
import com.xpn.xwiki.web.XWikiServletResponseStub;
4446

47+
import static org.junit.jupiter.api.Assertions.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4549
import static org.junit.jupiter.api.Assertions.assertTrue;
4650

4751
/**
@@ -81,6 +85,19 @@ void setUp() throws Exception
8185
loadPage(SOLR_SEARCH_MACROS_REFERENCE);
8286
}
8387

88+
@Test
89+
void noEmptyParagraph() throws Exception
90+
{
91+
// Prevent that the search UI triggers a redirect.
92+
this.request.put("r", "1");
93+
Document searchDocument = renderHTMLPage(SOLR_SEARCH_REFERENCE);
94+
Element firstElement = searchDocument.body().firstElementChild();
95+
assertNotNull(firstElement);
96+
// When there is whitespace inserted in the Velocity macro output, the first tag is a paragraph instead.
97+
assertEquals("div", firstElement.tagName());
98+
assertEquals("search-ui", firstElement.className());
99+
}
100+
84101
@Test
85102
void checkRSSFeedContent() throws Exception
86103
{

xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/main/resources/templates/macros.vm

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,13 +2070,14 @@ $displayName##
20702070
* @since 16.10.11
20712071
*#
20722072
#macro(validateQueryLimit $limit $parameterName)
2073-
#set ($configuredLimit = $services.security.getQueryItemsLimit())
2074-
#if ($configuredLimit > 0 && ($limit < 0 || $limit > $configuredLimit))
2075-
#set($discard =
2076-
$response.sendError(400,
2077-
"Invalid parameter value $limit for $parameterName: Must be a positive integer and less than or equal to $configuredLimit"))
2078-
#stop
2079-
#end
2073+
## This macro is used in places that are sensitive to whitespace - don't indent.
2074+
#set ($configuredLimit = $services.security.getQueryItemsLimit())
2075+
#if ($configuredLimit > 0 && ($limit < 0 || $limit > $configuredLimit))
2076+
#set($discard =
2077+
$response.sendError(400,
2078+
"Invalid parameter value $limit for $parameterName: Must be a positive integer and less than or equal to $configuredLimit"))
2079+
#stop
2080+
#end
20802081
#end
20812082
##
20822083
##
@@ -2091,14 +2092,15 @@ $displayName##
20912092
* @since 16.10.11
20922093
*#
20932094
#macro(getAndValidateQueryLimitFromRequest $parameterName $defaultValue $_limit)
2094-
#set ($return = $numbertool.toNumber("$!{request.get($parameterName)}").intValue())
2095-
#if (!$return)
2096-
#set ($return = $defaultValue)
2097-
#else
2098-
#validateQueryLimit($return $parameterName)
2099-
#end
2100-
#set ($_limit = $NULL)
2101-
#setVariable("$_limit" $return)
2095+
## This macro is used in places that are sensitive to whitespace - don't indent.
2096+
#set ($return = $numbertool.toNumber("$!{request.get($parameterName)}").intValue())
2097+
#if (!$return)
2098+
#set ($return = $defaultValue)
2099+
#else
2100+
#validateQueryLimit($return $parameterName)
2101+
#end
2102+
#set ($_limit = $NULL)
2103+
#setVariable("$_limit" $return)
21022104
#end
21032105
##
21042106
##

0 commit comments

Comments
 (0)