Skip to content

Commit

Permalink
Strip unwanted quotes from soapAction header
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Nov 22, 2023
1 parent f9aad91 commit d06afc5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
"php-soap/engine-integration-tests": "^1.4",
"phpunit/phpunit": "^10.0",
"guzzlehttp/guzzle": "^7.5"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
5 changes: 3 additions & 2 deletions src/HttpBinding/SoapActionDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ final class SoapActionDetector
{
public static function detectFromRequest(RequestInterface $request): string
{
$normalize = static fn(string $action): string => trim($action, '"\'');
$header = $request->getHeader('SOAPAction');
if ($header) {
return $header[0];
return $normalize($header[0]);
}

$contentTypes = $request->getHeader('Content-Type');
if ($contentTypes) {
$contentType = $contentTypes[0];
foreach (explode(';', $contentType) as $part) {
if (strpos($part, 'action=') !== false) {
return trim(explode('=', $part)[1], '"\'');
return $normalize(explode('=', $part)[1]);
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions tests/Unit/HttpBinding/SoapActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ public function test_it_can_detect_soap_action_from_soap_11__soap_action_header(
static::assertSame('actionhere', $result);
}


public function test_it_strips_out_additional_quotes_from_header_value()
{
$request = $this->createRequest()->withAddedHeader('SoapAction', '"actionhere"');
$result = (new SoapActionDetector())->detectFromRequest($request);

static::assertSame('actionhere', $result);
}

public function test_it_can_detect_soap_action_from_soap_12_content_type_header_with_double_quote()
{
$request = $this->createRequest()
Expand All @@ -30,7 +37,7 @@ public function test_it_can_detect_soap_action_from_soap_12_content_type_header_
static::assertSame('actionhere', $result);
}


public function test_it_can_detect_soap_action_from_soap_12_content_type_header_with_single_quote()
{
$request = $this->createRequest()
Expand All @@ -40,7 +47,7 @@ public function test_it_can_detect_soap_action_from_soap_12_content_type_header_
static::assertSame('actionhere', $result);
}


public function test_it_throws_an_http_request_exception_when_no_header_could_be_found()
{
$this->expectException(RequestException::class);
Expand Down

0 comments on commit d06afc5

Please sign in to comment.