8000 Merge branch '5.1' into 5.2 · symfony/symfony@bdadbf3 · GitHub
[go: up one dir, main page]

Skip to content

Commit bdadbf3

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: Display debug info [HttpClient] don't fallback to HTTP/1.1 when HTTP/2 streams break fix lexing nested sequences/mappings
2 parents af8bd4b + 634d168 commit bdadbf3

File tree

6 files changed

+319
-83
lines changed

6 files changed

+319
-83
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,12 @@ jobs:
9999

100100
- name: Install system dependencies
101101
run: |
102-
echo "::group::add apt sources"
103-
sudo wget -O - http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
104-
echo "deb http://packages.couchbase.com/ubuntu bionic bionic/main" | sudo tee /etc/apt/sources.list.d/couchbase.list
105-
echo "::endgroup::"
106-
107102
echo "::group::apt-get update"
108103
sudo apt-get update
109104
echo "::endgroup::"
110105
111106
echo "::group::install tools & libraries"
112-
sudo apt-get install libcouchbase-dev librdkafka-dev
107+
sudo apt-get install librdkafka-dev
113108
echo "::endgroup::"
114109
115110
- name: Configure Couchbase
@@ -128,6 +123,11 @@ jobs:
128123
php-version: "${{ matrix.php }}"
129124
tools: pecl
130125

126+
- name: Display versions
127+
run: |
128+
php -r 'foreach (get_loaded_extensions() as $extension) echo $extension . " " . phpversion($extension) . PHP_EOL;'
129+
php -i
130+
131131
- name: Load fixtures
132132
uses: docker://bitnami/openldap
133133
with:

src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CouchbaseBucketAdapter extends AbstractAdapter
4242
public function __construct(\CouchbaseBucket $bucket, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
4343
{
4444
if (!static::isSupported()) {
45-
throw new CacheException('Couchbase >= 2.6.0 is required.');
45+
throw new CacheException('Couchbase >= 2.6.0 < 3.0.0 is required.');
4646
}
4747

4848
$this->maxIdLength = static::MAX_KEY_LENGTH;
@@ -66,7 +66,7 @@ public static function createConnection($servers, array $options = []): \Couchba
6666
}
6767

6868
if (!static::isSupported()) {
69-
throw new CacheException('Couchbase >= 2.6.0 is required.');
69+
throw new CacheException('Couchbase >= 2.6.0 < 3.0.0 is required.');
7070
}
7171

7272
set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
@@ -125,7 +125,7 @@ public static function createConnection($servers, array $options = []): \Couchba
125125

126126
public static function isSupported(): bool
127127
{
128-
return \extension_loaded('couchbase') && version_compare(phpversion('couchbase'), '2.6.0', '>=');
128+
return \extension_loaded('couchbase') && version_compare(phpversion('couchbase'), '2.6.0', '>=') && version_compare(phpversion('couchbase'), '3.0', '<');
129129
}
130130

131131
private static function getOptions(string $options): array

src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;
1717

1818
/**
19-
* @requires extension couchbase 2.6.0
19+
* @requires extension couchbase <3.0.0
20+
* @requires extension couchbase >=2.6.0
2021
* @group integration
2122
*
2223
* @author Antonio Jose Cerezo Aranda <aj.cerezo@gmail.com>
@@ -32,6 +33,10 @@ class CouchbaseBucketAdapterTest extends AdapterTestCase
3233

3334
public static function setupBeforeClass(): void
3435
{
36+
if (!CouchbaseBucketAdapter::isSupported()) {
37+
self::markTestSkipped('Couchbase >= 2.6.0 < 3.0.0 is required.');
38+
}
39+
3540
self::$client = AbstractAdapter::createConnection('couchbase://'.getenv('COUCHBASE_HOST').'/cache',
3641
['username' => getenv('COUCHBASE_USER'), 'password' => getenv('COUCHBASE_PASS')]
3742
);

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,7 @@ private static function perform(ClientState $multi, array &$responses = null): v
306306
curl_multi_remove_handle($multi->handle, $ch);
307307
$waitFor[1] = (string) ((int) $waitFor[1] - 1); // decrement the retry counter
308308
curl_setopt($ch, \CURLOPT_PRIVATE, $waitFor);
309-
310-
if ('1' === $waitFor[1]) {
311-
curl_setopt($ch, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1);
312-
}
309+
curl_setopt($ch, \CURLOPT_FORBID_REUSE, true);
313310

314311
if (0 === curl_multi_add_handle($multi->handle, $ch)) {
315312
continue;

src/Symfony/Component/Yaml/Parser.php

Lines changed: 119 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private function doParse(string $value, int $flags)
358358
}
359359

360360
try {
361-
return Inline::parse($this->parseQuotedString($this->currentLine), $flags, $this->refs);
361+
return Inline::parse($this->lexInlineQuotedString(), $flags, $this->refs);
362362
} catch (ParseException $e) {
363363
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
364364
$e->setSnippet($this->currentLine);
@@ -371,7 +371,7 @@ private function doParse(string $value, int $flags)
371371
}
372372

373373
try {
374-
$parsedMapping = Inline::parse($this->lexInlineMapping($this->currentLine), $flags, $this->refs);
374+
$parsedMapping = Inline::parse($this->lexInlineMapping(), $flags, $this->refs);
375375

376376
while ($this->moveToNextLine()) {
377377
if (!$this->isCurrentLineEmpty()) {
@@ -392,7 +392,7 @@ private function doParse(string $value, int $flags)
392392
}
393393

394394
try {
395-
$parsedSequence = Inline::parse($this->lexInlineSequence($this->currentLine), $flags, $this->refs);
395+
$parsedSequence = Inline::parse($this->lexInlineSequence(), $flags, $this->refs);
396396

397397
while ($this->moveToNextLine()) {
398398
if (!$this->isCurrentLineEmpty()) {
@@ -667,6 +667,11 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f
667667
return implode("\n", $data);
668668
}
669669

670+
private function hasMoreLines(): bool
671+
{
672+
return (\count($this->lines) - 1) > $this->currentLineNb;
673+
}
674+
670675
/**
671676
* Moves the parser to the next line.
672677
*/
@@ -744,9 +749,13 @@ private function parseValue(string $value, int $flags, string $context)
744749

745750
try {
746751
if ('' !== $value && '{' === $value[0]) {
747-
return Inline::parse($this->lexInlineMapping($value), $flags, $this->refs);
752+
$cursor = \strlen($this->currentLine) - \strlen($value);
753+
754+
return Inline::parse($this->lexInlineMapping($cursor), $flags, $this->refs);
748755
} elseif ('' !== $value && '[' === $value[0]) {
749-
return Inline::parse($this->lexInlineSequence($value), $flags, $this->refs);
756+
$cursor = \strlen($this->currentLine) - \strlen($value);
757+
758+
return Inline::parse($this->lexInlineSequence($cursor), $flags, $this->refs);
750759
}
751760

752761
$quotation = '' !== $value && ('"' === $value[0] || "'" === $value[0]) ? $value[0] : null;
@@ -1145,107 +1154,148 @@ private function getLineTag(string $value, int $flags, bool $nextLineCheck = tru
11451154
throw new ParseException(sprintf('Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "%s".', $matches['tag']), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
11461155
}
11471156

1148-
private function parseQuotedString(string $yaml): ?string
1157+
private function lexInlineQuotedString(int &$cursor = 0): string
11491158
{
1150-
if ('' === $yaml || ('"' !== $yaml[0] && "'" !== $yaml[0])) {
1151-
throw new \InvalidArgumentException(sprintf('"%s" is not a quoted string.', $yaml));
1152-
}
1159+
$quotation = $this->currentLine[$cursor];
1160+
$value = $quotation;
1161+
++$cursor;
11531162

1154-
$lines = [$yaml];
1155-
1156-
while ($this->moveToNextLine()) {
1157-
$lines[] = $this->currentLine;
1163+
$previousLineWasNewline = true;
1164+
$previousLineWasTerminatedWithBackslash = false;
11581165

1159-
if (!$this->isCurrentLineEmpty() && $yaml[0] === $this->currentLine[-1]) {
1160-
break;
1161-
}
1162-
}
1163-
1164-
$value = '';
1165-
1166-
for ($i = 0, $linesCount = \count($lines), $previousLineWasNewline = false, $previousLineWasTerminatedWithBackslash = false; $i < $linesCount; ++$i) {
1167-
$trimmedLine = trim($lines[$i]);
1168-
if ('' === $trimmedLine) {
1166+
do {
1167+
if ($this->isCurrentLineBlank()) {
11691168
$value .= "\n";
11701169
} elseif (!$previousLineWasNewline && !$previousLineWasTerminatedWithBackslash) {
11711170
$value .= ' ';
11721171
}
11731172

1174-
if ('' !== $trimmedLine && '\\' === $lines[$i][-1]) {
1175-
$value .= ltrim(substr($lines[$i], 0, -1));
1176-
} elseif ('' !== $trimmedLine) {
1177-
$value .= $trimmedLine;
1173+
for (; \strlen($this->currentLine) > $cursor; ++$cursor) {
1174+
switch ($this->currentLine[$cursor]) {
1175+
case '\\':
1176+
if (isset($this->currentLine[++$cursor])) {
1177+
$value .= '\\'.$this->currentLine[$cursor];
1178+
}
1179+
1180+
break;
1181+
case $quotation:
1182+
++$cursor;
1183+
1184+
if ("'" === $quotation && isset($this->currentLine[$cursor]) && "'" === $this->currentLine[$cursor]) {
1185+
$value .= "''";
1186+
break;
1187+
}
1188+
1189+
return $value.$quotation;
1190+
default:
1191+
$value .= $this->currentLine[$cursor];
1192+
}
11781193
}
11791194

1180-
if ('' === $trimmedLine) {
1195+
if ($this->isCurrentLineBlank()) {
11811196
$previousLineWasNewline = true;
11821197
$previousLineWasTerminatedWithBackslash = false;
1183-
} elseif ('\\' === $lines[$i][-1]) {
1198+
} elseif ('\\' === $this->currentLine[-1]) {
11841199
$previousLineWasNewline = false;
11851200
$previousLineWasTerminatedWithBackslash = true;
11861201
} else {
11871202
$previousLineWasNewline = false;
11881203
$previousLineWasTerminatedWithBackslash = false;
11891204
}
1190-
}
11911205

1192-
return $value;
1206+
if ($this->hasMoreLines()) {
1207+
$cursor = 0;
1208+
}
1209+
} while ($this->moveToNextLine());
1210+
1211+
throw new ParseException('Malformed inline YAML string');
11931212
}
11941213

1195-
private function lexInlineMapping(string $yaml): string
1214+
private function lexUnquotedString(int &$cursor): string
11961215
{
1197-
if ('' === $yaml || '{' !== $yaml[0]) {
1198-
throw new \InvalidArgumentException(sprintf('"%s" is not a sequence.', $yaml));
1199-
}
1200-
1201-
for ($i = 1; isset($yaml[$i]) && '}' !== $yaml[$i]; ++$i) {
1202-
}
1216+
$offset = $cursor;
1217+
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
12031218

1204-
if (isset($yaml[$i]) && '}' === $yaml[$i]) {
1205-
return $yaml;
1206-
}
1207-
1208-
$lines = [$yaml];
1209-
1210-
while ($this->moveToNextLine()) {
1211-
$lines[] = $this->currentLine;
1212-
}
1219+
return substr($this->currentLine, $offset, $cursor - $offset);
1220+
}
12131221

1214-
return implode("\n", $lines);
1222+
private function lexInlineMapping(int &$cursor = 0): string
1223+
{
1224+
return $this->lexInlineStructure($cursor, '}');
12151225
}
12161226

1217-
private function lexInlineSequence(string $yaml): string
1227+
private function lexInlineSequence(int &$cursor = 0): string
12181228
{
1219-
if ('' === $yaml || '[' !== $yaml[0]) {
1220-
throw new \InvalidArgumentException(sprintf('"%s" is not a sequence.', $yaml));
1221-
}
1229+
return $this->lexInlineStructure($cursor, ']');
1230+
}
12221231

1223-
for ($i = 1; isset($yaml[$i]) && ']' !== $yaml[$i]; ++$i) {
1224-
}
1232+
private function lexInlineStructure(int &$cursor, string $closingTag): string
1233+
{
1234+
$value = $this->currentLine[$cursor];
1235+
++$cursor;
12251236

1226-
if (isset($yaml[$i]) && ']' === $yaml[$i]) {
1227-
return $yaml;
1228-
}
1237+
do {
1238+
$this->consumeWhitespaces($cursor);
1239+
1240+
while (isset($this->currentLine[$cursor])) {
1241+
switch ($this->currentLine[$cursor]) {
1242+
case '"':
1243+
case "'":
1244+
$value .= $this->lexInlineQuotedString($cursor);
1245+
break;
1246+
case ':':
1247+
case ',':
1248+
$value .= $this->currentLine[$cursor];
1249+
++$cursor;
1250+
break;
1251+
case '{':
1252+
$value .= $this->lexInlineMapping($cursor);
1253+
break;
1254+
case '[':
1255+
$value .= $this->lexInlineSequence($cursor);
1256+
break;
1257+
case $closingTag:
1258+
$value .= $this->currentLine[$cursor];
1259+
++$cursor;
1260+
1261+
return $value;
1262+
case '#':
1263+
break 2;
1264+
default:
1265+
$value .= $this->lexUnquotedString($cursor);
1266+
}
12291267

1230-
$value = $yaml;
1268+
if ($this->consumeWhitespaces($cursor)) {
1269+
$value .= ' ';
1270+
}
1271+
}
12311272

1232-
while ($this->moveToNextLine()) {
1233-
for ($i = 1; isset($this->currentLine[$i]) && ']' !== $this->currentLine[$i]; ++$i) {
1273+
if ($this->hasMoreLines()) {
1274+
$cursor = 0;
12341275
}
1276+
} while ($this->moveToNextLine());
12351277

1236-
$trimmedValue = trim($this->currentLine);
1278+
throw new ParseException('Malformed inline YAML string');
1279+
}
12371280

1238-
if ('' !== $trimmedValue && '#' === $trimmedValue[0]) {
1239-
continue;
1240-
}
1281+
private function consumeWhitespaces(int &$cursor): bool
1282+
{
1283+
$whitespacesConsumed = 0;
12411284

1242-
$value .= $trimmedValue;
1285+
do {
1286+
$whitespaceOnlyTokenLength = strspn($this->currentLine, ' ', $cursor);
1287+
$whitespacesConsumed += $whitespaceOnlyTokenLength;
1288+
$cursor += $whitespaceOnlyTokenLength;
12431289

1244-
if (isset($this->currentLine[$i]) && ']' === $this->currentLine[$i]) {
1245-
break;
1290+
if (isset($this->currentLine[$cursor])) {
1291+
return 0 < $whitespacesConsumed;
12461292
}
1247-
}
12481293

1249-
return $value;
1294+
if ($this->hasMoreLines()) {
1295+
$cursor = 0;
1296+
}
1297+
} while ($this->moveToNextLine());
1298+
1299+
return 0 < $whitespacesConsumed;
12501300
}
12511301
}

0 commit comments

Comments
 (0)
0