Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!![TASK] Remove JSONP callback in suggest #4267

Open
wants to merge 1 commit into
base: release-12.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Classes/Controller/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SuggestController extends AbstractBaseController
*
* @noinspection PhpUnused
*/
public function suggestAction(string $queryString, ?string $callback = null, ?array $additionalFilters = []): ResponseInterface
public function suggestAction(string $queryString, ?array $additionalFilters = []): ResponseInterface
{
// Get suggestions
$rawQuery = htmlspecialchars(mb_strtolower(trim($queryString)));
Expand Down Expand Up @@ -65,9 +65,6 @@ public function suggestAction(string $queryString, ?string $callback = null, ?ar
} catch (SolrUnavailableException) {
return $this->handleSolrUnavailable();
}
if ($callback) {
return $this->htmlResponse(htmlspecialchars($callback) . '(' . json_encode($result, JSON_UNESCAPED_SLASHES) . ')');
}
return $this->htmlResponse(json_encode($result, JSON_UNESCAPED_SLASHES));
}

Expand Down
6 changes: 1 addition & 5 deletions Configuration/TypoScript/Examples/Suggest/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tx_solr_suggest {
disableAllHeaderCode = 1
xhtml_cleaning = 0
admPanel = 0
additionalHeaders.10.header = Content-type: application/javascript
additionalHeaders.10.header = Content-type: application/json
no_cache = 0
debug = 0
}
Expand All @@ -23,10 +23,6 @@ tx_solr_suggest {
}
}

[request && traverse(request.getQueryParams(), 'tx_solr/callback') == '']
tx_solr_suggest.config.additionalHeaders.10.header = Content-type: application/json
[global]

# Enable suggest
plugin.tx_solr {
suggest = 1
Expand Down
8 changes: 8 additions & 0 deletions Documentation/Releases/solr-release-12-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ Releases 12.0

.. include:: HintAboutOutdatedChangelog.rst.txt

Release 12.0.6
==============

This is a maintenance release for TYPO3 12.4 LTS, containing:

- !!![TASK] Remove JSONP callback in suggest by @bmack in `#4267 <https://github.com/TYPO3-Solr/ext-solr/pull/4267>`__
By own implementation of autosuggest JS parts with usage of JSONP, the action must be migrated to non-JSONP calls.

Release 12.0.5
==============

Expand Down
5 changes: 1 addition & 4 deletions Resources/Public/JavaScript/suggest_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ function SuggestController() {

$form.find('.tx-solr-suggest').devbridgeAutocomplete({
serviceUrl: $form.data('suggest'),
dataType: 'jsonp',
ajaxSettings: {
jsonp: "tx_solr[callback]"
},
dataType: 'json',
paramName: 'tx_solr[queryString]',
groupBy: 'category',
maxHeight: 1000,
Expand Down
19 changes: 2 additions & 17 deletions Tests/Integration/Controller/SuggestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ public function canDoABasicSuggest(): void
$this->importCSVDataSet(__DIR__ . '/Fixtures/indexing_data.csv');
$this->indexPages([1, 2, 3, 4, 5, 6, 7, 8]);

$result = (string)($this->executeFrontendSubRequestForSuggestQueryString('Sweat', 'rand')->getBody());

// we assume to get suggestions like Sweatshirt
self::assertStringContainsString('suggestions":{"sweatshirts":2}', $result, 'Response did not contain sweatshirt suggestions');
}

#[Test]
public function canDoABasicSuggestWithoutCallback(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/indexing_data.csv');
$this->indexPages([1, 2, 3, 4, 5, 6, 7, 8]);

$result = (string)($this->executeFrontendSubRequestForSuggestQueryString('Sweat')->getBody());

// we assume to get suggestions like Sweatshirt
Expand Down Expand Up @@ -112,23 +100,20 @@ public function canSuggestWithUriSpecialChars(): void

protected function expectSuggested(string $prefix, string $expected)
{
$result = (string)($this->executeFrontendSubRequestForSuggestQueryString($prefix, 'rand')->getBody());
$result = (string)($this->executeFrontendSubRequestForSuggestQueryString($prefix)->getBody());

//we assume to get suggestions like some/large/path
self::assertStringContainsString($expected, $result, 'Response did not contain expected suggestions: ' . $expected);
}

protected function executeFrontendSubRequestForSuggestQueryString(string $queryString, ?string $callback = null): ResponseInterface
protected function executeFrontendSubRequestForSuggestQueryString(string $queryString): ResponseInterface
{
$request = new InternalRequest('http://testone.site/en/');
$request = $request
->withPageId(1)
->withQueryParameter('type', '7384')
->withQueryParameter('tx_solr[queryString]', $queryString);

if ($callback !== null) {
$request = $request->withQueryParameter('tx_solr[callback]', $callback);
}
return $this->executeFrontendSubRequest($request);
}
}
Loading