Skip to content

Commit 3c59bd5

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1856 from magento-engcom/2.2-develop-prs
Public Pull Requests - #11070 Remove deprecation without alternative by @schmengler - magento-engcom#949 8615: REST API unable to make requests with slash (/) in SKU by @RomaKis Fixed Public Issues - #10133 Please add your expectations for @deprecated annotations - #8615 REST API unable to make requests with slash (/) in SKU
2 parents 3e3e8fc + 96c8e96 commit 3c59bd5

File tree

10 files changed

+321
-20
lines changed

10 files changed

+321
-20
lines changed

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
/**
1515
* Shopping cart model
16+
*
1617
* @api
1718
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18-
* @deprecated 100.1.0
19+
* @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
1920
*/
2021
class Cart extends DataObject implements CartInterface
2122
{

app/code/Magento/Checkout/Model/Cart/CartInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @api
1414
* @author Magento Core Team <[email protected]>
15-
* @deprecated 100.1.0
15+
* @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead
1616
*/
1717
interface CartInterface
1818
{

app/code/Magento/Webapi/Controller/Rest/InputParamsResolver.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
namespace Magento\Webapi\Controller\Rest;
88

9-
use Magento\Framework\Webapi\ServiceInputProcessor;
109
use Magento\Framework\Webapi\Rest\Request as RestRequest;
11-
use Magento\Webapi\Controller\Rest\Router;
10+
use Magento\Framework\Webapi\ServiceInputProcessor;
1211
use Magento\Webapi\Controller\Rest\Router\Route;
12+
use Magento\Webapi\Model\UrlDecoder;
1313

1414
/**
1515
* This class is responsible for retrieving resolved input data
@@ -47,26 +47,32 @@ class InputParamsResolver
4747
private $requestValidator;
4848

4949
/**
50-
* Initialize dependencies
51-
*
50+
* @var UrlDecoder
51+
*/
52+
private $urlDecoder;
53+
54+
/**
5255
* @param RestRequest $request
5356
* @param ParamsOverrider $paramsOverrider
5457
* @param ServiceInputProcessor $serviceInputProcessor
5558
* @param Router $router
5659
* @param RequestValidator $requestValidator
60+
* @param UrlDecoder $urlDecoder
5761
*/
5862
public function __construct(
5963
RestRequest $request,
6064
ParamsOverrider $paramsOverrider,
6165
ServiceInputProcessor $serviceInputProcessor,
6266
Router $router,
63-
RequestValidator $requestValidator
67+
RequestValidator $requestValidator,
68+
UrlDecoder $urlDecoder = null
6469
) {
6570
$this->request = $request;
6671
$this->paramsOverrider = $paramsOverrider;
6772
$this->serviceInputProcessor = $serviceInputProcessor;
6873
$this->router = $router;
6974
$this->requestValidator = $requestValidator;
75+
$this->urlDecoder = $urlDecoder ?: \Magento\Framework\App\ObjectManager::getInstance()->get(UrlDecoder::class);
7076
}
7177

7278
/**
@@ -97,6 +103,7 @@ public function resolve()
97103
$inputData = $this->request->getRequestData();
98104
}
99105

106+
$inputData = $this->urlDecoder->decodeParams($inputData);
100107
$inputData = $this->paramsOverrider->override($inputData, $route->getParameters());
101108
$inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData);
102109
return $inputParams;

app/code/Magento/Webapi/Controller/Soap/Request/Handler.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Webapi\Model\Soap\Config as SoapConfig;
1818
use Magento\Framework\Reflection\MethodsMap;
1919
use Magento\Webapi\Model\ServiceMetadata;
20+
use Magento\Webapi\Model\UrlDecoder;
2021

2122
/**
2223
* Handler of requests to SOAP server.
@@ -70,8 +71,11 @@ class Handler
7071
protected $methodsMapProcessor;
7172

7273
/**
73-
* Initialize dependencies.
74-
*
74+
* @var UrlDecoder
75+
*/
76+
private $urlDecoder;
77+
78+
/**
7579
* @param SoapRequest $request
7680
* @param \Magento\Framework\ObjectManagerInterface $objectManager
7781
* @param SoapConfig $apiConfig
@@ -80,6 +84,7 @@ class Handler
8084
* @param ServiceInputProcessor $serviceInputProcessor
8185
* @param DataObjectProcessor $dataObjectProcessor
8286
* @param MethodsMap $methodsMapProcessor
87+
* @param UrlDecoder $urlDecoder
8388
*/
8489
public function __construct(
8590
SoapRequest $request,
@@ -89,7 +94,8 @@ public function __construct(
8994
SimpleDataObjectConverter $dataObjectConverter,
9095
ServiceInputProcessor $serviceInputProcessor,
9196
DataObjectProcessor $dataObjectProcessor,
92-
MethodsMap $methodsMapProcessor
97+
MethodsMap $methodsMapProcessor,
98+
UrlDecoder $urlDecoder = null
9399
) {
94100
$this->_request = $request;
95101
$this->_objectManager = $objectManager;
@@ -99,6 +105,7 @@ public function __construct(
99105
$this->serviceInputProcessor = $serviceInputProcessor;
100106
$this->_dataObjectProcessor = $dataObjectProcessor;
101107
$this->methodsMapProcessor = $methodsMapProcessor;
108+
$this->urlDecoder = $urlDecoder ?: \Magento\Framework\App\ObjectManager::getInstance()->get(UrlDecoder::class);
102109
}
103110

104111
/**
@@ -150,6 +157,7 @@ protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments
150157
/** SoapServer wraps parameters into array. Thus this wrapping should be removed to get access to parameters. */
151158
$arguments = reset($arguments);
152159
$arguments = $this->_dataObjectConverter->convertStdObjectToArray($arguments, true);
160+
$arguments = $this->urlDecoder->decodeParams($arguments);
153161
return $this->serviceInputProcessor->process($serviceClass, $serviceMethod, $arguments);
154162
}
155163

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Webapi\Model;
8+
9+
/**
10+
* Url decoder.
11+
*/
12+
class UrlDecoder
13+
{
14+
/**
15+
* Decode request params.
16+
*
17+
* @param array $params
18+
*
19+
* @return array
20+
*/
21+
public function decodeParams(array $params)
22+
{
23+
foreach ($params as &$param) {
24+
if (is_array($param)) {
25+
$param = $this->decodeParams($param);
26+
} else {
27+
if ($param !== null && is_string($param)) {
28+
$param = rawurldecode($param);
29+
}
30+
}
31+
}
32+
33+
return $params;
34+
}
35+
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
4747
ProductInterface::TYPE_ID => 'simple',
4848
ProductInterface::PRICE => 10
4949
],
50+
[
51+
ProductInterface::SKU => [
52+
'rest' => 'sku%252fwith%252fslashes',
53+
'soap' => 'sku%2fwith%2fslashes'
54+
],
55+
ProductInterface::NAME => 'Simple Product with Sku with Slashes',
56+
ProductInterface::TYPE_ID => 'simple',
57+
ProductInterface::PRICE => 10
58+
],
5059
];
5160

5261
/**
@@ -135,6 +144,20 @@ public function productCreationProvider()
135144
];
136145
}
137146

147+
/**
148+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_sku_with_slash.php
149+
*/
150+
public function testGetBySkuWithSlash()
151+
{
152+
$productData = $this->productData[2];
153+
$response = $this->getProduct($productData[ProductInterface::SKU][TESTS_WEB_API_ADAPTER]);
154+
$productData[ProductInterface::SKU] = rawurldecode($productData[ProductInterface::SKU]['soap']);
155+
foreach ([ProductInterface::SKU, ProductInterface::NAME, ProductInterface::PRICE] as $key) {
156+
$this->assertEquals($productData[$key], $response[$key]);
157+
}
158+
$this->assertEquals([1], $response[ProductInterface::EXTENSION_ATTRIBUTES_KEY]["website_ids"]);
159+
}
160+
138161
/**
139162
* Test removing association between product and website 1
140163
* @magentoApiDataFixture Magento/Catalog/_files/product_with_two_websites.php

0 commit comments

Comments
 (0)