Skip to content

Commit 65e1fd0

Browse files
authored
Merge pull request #15 from php-soap/improve-action-detector
Strip unwanted quotes from soapAction header
2 parents f9aad91 + 020168b commit 65e1fd0

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

composer.json

+5
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@
4141
"php-soap/engine-integration-tests": "^1.4",
4242
"phpunit/phpunit": "^10.0",
4343
"guzzlehttp/guzzle": "^7.5"
44+
},
45+
"config": {
46+
"allow-plugins": {
47+
"php-http/discovery": true
48+
}
4449
}
4550
}

src/HttpBinding/SoapActionDetector.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ final class SoapActionDetector
1111
{
1212
public static function detectFromRequest(RequestInterface $request): string
1313
{
14+
$normalize = static fn (string $action): string => trim($action, '"\'');
1415
$header = $request->getHeader('SOAPAction');
1516
if ($header) {
16-
return $header[0];
17+
return $normalize($header[0]);
1718
}
1819

1920
$contentTypes = $request->getHeader('Content-Type');
2021
if ($contentTypes) {
2122
$contentType = $contentTypes[0];
2223
foreach (explode(';', $contentType) as $part) {
2324
if (strpos($part, 'action=') !== false) {
24-
return trim(explode('=', $part)[1], '"\'');
25+
return $normalize(explode('=', $part)[1]);
2526
}
2627
}
2728
}

tests/Unit/HttpBinding/SoapActionTest.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ public function test_it_can_detect_soap_action_from_soap_11__soap_action_header(
1919
static::assertSame('actionhere', $result);
2020
}
2121

22-
22+
public function test_it_strips_out_additional_quotes_from_header_value()
23+
{
24+
$request = $this->createRequest()->withAddedHeader('SoapAction', '"actionhere"');
25+
$result = (new SoapActionDetector())->detectFromRequest($request);
26+
27+
static::assertSame('actionhere', $result);
28+
}
29+
2330
public function test_it_can_detect_soap_action_from_soap_12_content_type_header_with_double_quote()
2431
{
2532
$request = $this->createRequest()
@@ -30,7 +37,7 @@ public function test_it_can_detect_soap_action_from_soap_12_content_type_header_
3037
static::assertSame('actionhere', $result);
3138
}
3239

33-
40+
3441
public function test_it_can_detect_soap_action_from_soap_12_content_type_header_with_single_quote()
3542
{
3643
$request = $this->createRequest()
@@ -40,7 +47,7 @@ public function test_it_can_detect_soap_action_from_soap_12_content_type_header_
4047
static::assertSame('actionhere', $result);
4148
}
4249

43-
50+
4451
public function test_it_throws_an_http_request_exception_when_no_header_could_be_found()
4552
{
4653
$this->expectException(RequestException::class);

0 commit comments

Comments
 (0)