Merge pull request #19232 from jtattermusch/php_dots_in_metadata_keys

PHP: Allow dots in metadata keys
pull/19280/head
Stanley Cheung 6 years ago committed by GitHub
commit c63b8e16a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/php/lib/Grpc/BaseStub.php
  2. 27
      src/php/tests/generated_code/AbstractGeneratedCodeTest.php

@ -241,10 +241,10 @@ class BaseStub
{
$metadata_copy = [];
foreach ($metadata as $key => $value) {
if (!preg_match('/^[A-Za-z\d_-]+$/', $key)) {
if (!preg_match('/^[.A-Za-z\d_-]+$/', $key)) {
throw new \InvalidArgumentException(
'Metadata keys must be nonempty strings containing only '.
'alphanumeric characters, hyphens and underscores'
'alphanumeric characters, hyphens, underscores and dots'
);
}
$metadata_copy[strtolower($key)] = $value;

@ -71,6 +71,33 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase
$call = self::$client->Div($div_arg, [' ' => 'abc123']);
}
public function testMetadata()
{
$div_arg = new Math\DivArgs();
$call = self::$client->Div($div_arg, ['somekey' => ['abc123']]);
}
public function testMetadataKey()
{
$div_arg = new Math\DivArgs();
$call = self::$client->Div($div_arg, ['somekey_-1' => ['abc123']]);
}
public function testMetadataKeyWithDot()
{
$div_arg = new Math\DivArgs();
$call = self::$client->Div($div_arg, ['someKEY._-1' => ['abc123']]);
}
/**
* @expectedException InvalidArgumentException
*/
public function testMetadataInvalidKey()
{
$div_arg = new Math\DivArgs();
$call = self::$client->Div($div_arg, ['(somekey)' => ['abc123']]);
}
public function testGetCallMetadata()
{
$div_arg = new Math\DivArgs();

Loading…
Cancel
Save