Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 58254fe

Browse filesBrowse files
[Cache] Add support for URL encoded characters in Couchbase DSN
1 parent ad17267 commit 58254fe
Copy full SHA for 58254fe

File tree

6 files changed

+41
-18
lines changed
Filter options

6 files changed

+41
-18
lines changed

‎.github/workflows/integration-tests.yml

Copy file name to clipboardExpand all lines: .github/workflows/integration-tests.yml
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ jobs:
132132
133133
- name: Configure Couchbase
134134
run: |
135-
curl -s -u 'username=Administrator&password=111111' -X POST http://localhost:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex%2Cfts'
136-
curl -s -X POST http://localhost:8091/settings/web -d 'username=Administrator&password=111111&port=SAME'
137-
curl -s -u Administrator:111111 -X POST http://localhost:8091/pools/default/buckets -d 'ramQuotaMB=100&bucketType=ephemeral&name=cache'
138-
curl -s -u Administrator:111111 -X POST http://localhost:8091/pools/default -d 'memoryQuota=256'
135+
curl -s -u 'username=Administrator&password=111111@' -X POST http://localhost:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex%2Cfts'
136+
curl -s -X POST http://localhost:8091/settings/web -d 'username=Administrator&password=111111%40&port=SAME'
137+
curl -s -u Administrator:111111@ -X POST http://localhost:8091/pools/default/buckets -d 'ramQuotaMB=100&bucketType=ephemeral&name=cache'
138+
curl -s -u Administrator:111111@ -X POST http://localhost:8091/pools/default -d 'memoryQuota=256'
139139
140140
- name: Setup PHP
141141
uses: shivammathur/setup-php@v2

‎phpunit.xml.dist

Copy file name to clipboardExpand all lines: phpunit.xml.dist
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<env name="ZOOKEEPER_HOST" value="localhost" />
2626
<env name="COUCHBASE_HOST" value="localhost" />
2727
<env name="COUCHBASE_USER" value="Administrator" />
28-
<env name="COUCHBASE_PASS" value="111111" />
28+
<env name="COUCHBASE_PASS" value="111111%40" />
2929
</php>
3030

3131
<testsuites>

‎src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $dsn
5959

6060
set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line));
6161

62-
$dsnPattern = '/^(?<protocol>couchbase(?:s)?)\:\/\/(?:(?<username>[^\:]+)\:(?<password>[^\@]{6,})@)?'
63-
.'(?<host>[^\:]+(?:\:\d+)?)(?:\/(?<bucketName>[^\/\?]+))(?:(?:\/(?<scopeName>[^\/]+))'
64-
.'(?:\/(?<collectionName>[^\/\?]+)))?(?:\/)?(?:\?(?<options>.*))?$/i';
65-
62+
$pathPattern = '/^(?:\/(?<bucketName>[^\/\?]+))(?:(?:\/(?<scopeName>[^\/]+))(?:\/(?<collectionName>[^\/\?]+)))?(?:\/)?$/';
6663
$newServers = [];
6764
$protocol = 'couchbase';
6865
try {
@@ -74,31 +71,32 @@ public static function createConnection(#[\SensitiveParameter] array|string $dsn
7471
throw new InvalidArgumentException('Invalid Couchbase DSN: it does not start with "couchbase:".');
7572
}
7673

77-
preg_match($dsnPattern, $server, $matches);
74+
$params = parse_url($server);
7875

79-
$username = $matches['username'] ?: $username;
80-
$password = $matches['password'] ?: $password;
81-
$protocol = $matches['protocol'] ?: $protocol;
76+
$username = $params['user'] ?? $username;
77+
$password = rawurldecode($params['pass'] ?? $password);
78+
$protocol = $params['scheme'] ?? $protocol;
8279

83-
if (isset($matches['options'])) {
84-
$optionsInDsn = self::getOptions($matches['options']);
80+
if (isset($params['query'])) {
81+
$optionsInDsn = self::getOptions($params['query']);
8582

8683
foreach ($optionsInDsn as $parameter => $value) {
8784
$options[$parameter] = $value;
8885
}
8986
}
9087

91-
$newServers[] = $matches['host'];
88+
$newServers[] = $params['host'];
9289
}
9390

94-
$option = isset($matches['options']) ? '?'.$matches['options'] : '';
91+
$option = isset($params['query']) ? '?'.$params['query'] : '';
9592
$connectionString = $protocol.'://'.implode(',', $newServers).$option;
9693

9794
$clusterOptions = new ClusterOptions();
9895
$clusterOptions->credentials($username, $password);
9996

10097
$client = new Cluster($connectionString, $clusterOptions);
10198

99+
preg_match($pathPattern, $params['path'] ?? '', $matches);
102100
$bucket = $client->bucket($matches['bucketName']);
103101
$collection = $bucket->defaultCollection();
104102
if (!empty($matches['scopeName'])) {

‎src/Symfony/Component/Cache/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add support for URL encoded characters in Couchbase DSN
8+
49
7.0
510
---
611

‎src/Symfony/Component/Cache/Tests/Adapter/CouchbaseCollectionAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/CouchbaseCollectionAdapterTest.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,24 @@ public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
5959

6060
return new CouchbaseCollectionAdapter($client, str_replace('\\', '.', __CLASS__), $defaultLifetime);
6161
}
62+
63+
/**
64+
* Couchbase consider expiration time greater than 30 days as an absolute timestamp.
65+
* This test case overrides parent to avoid this behavior for the "k2" item.
66+
*/
67+
public function testExpiration()
68+
{
69+
$cache = $this->createCachePool();
70+
$cache->save($cache->getItem('k1')->set('v1')->expiresAfter(2));
71+
$cache->save($cache->getItem('k2')->set('v2')->expiresAfter(86400));
72+
73+
sleep(3);
74+
$item = $cache->getItem('k1');
75+
$this->assertFalse($item->isHit());
76+
$this->assertNull($item->get(), "Item's value must be null when isHit() is false.");
77+
78+
$item = $cache->getItem('k2');
79+
$this->assertTrue($item->isHit());
80+
$this->assertSame('v2', $item->get());
81+
}
6282
}

‎src/Symfony/Component/Cache/phpunit.xml.dist

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/phpunit.xml.dist
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<env name="MEMCACHED_HOST" value="localhost" />
1616
<env name="COUCHBASE_HOST" value="localhost" />
1717
<env name="COUCHBASE_USER" value="Administrator" />
18-
<env name="COUCHBASE_PASS" value="111111" />
18+
<env name="COUCHBASE_PASS" value="111111%40" />
1919
</php>
2020

2121
<testsuites>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.