Skip to content

Commit 8c00813

Browse files
committed
Replace danielstjules/stringy with symfony/string
The former isn't maintained anymore and triggers some deprecations on PHP 8.1.
1 parent 15f2f30 commit 8c00813

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1212
### Changed
1313
- The `ResponseBuilder` now requires PSR-17 factories instead of a PHP-HTTP factory, to align it with the `Client`. This is only a breaking change in the rare case where you provide your own factory to the `ResponseBuilder`.
1414
- Removed `domainAliases` from constructor arguments. Please use `setDomainAliases()` on the instance instead.
15+
- Replaced [danielstjules/stringy](https://packagist.org/packages/danielstjules/stringy) with [symfony/string](https://packagist.org/packages/symfony/string). In some edge cases, mainly special or accented characters, this will affect how query parameters are transformed to a fixture.
1516

1617
### Removed
1718
- Dropped PHP <7.4 support.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The `ReponseBuilder` can be instructed to ignore certain query parameters using
6767
When configured, the provided parameters will be ignored when transforming requests to file paths.
6868
You should only provide the parameter name, not the value.
6969
This allows you to ignore 'dynamic' parameters that change in each test execution.
70-
Parameters are matched strictly, so 'foo' will match 'foo=bar', but not 'foo[]=bar'.
70+
Parameters are matched strictly, after url decoding, so 'foo' will match 'foo=bar', but not 'foo[]=bar'.
7171

7272
### Strict mode
7373
The `ReponseBuilder` can be set to strict mode using `setStrictMode(true)`.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
],
2424
"require": {
2525
"php": "^7.4|^8.0",
26-
"danielstjules/stringy": "^3.1",
2726
"php-http/discovery": "^1.4",
2827
"php-http/mock-client": "^1.5",
2928
"psr/http-factory": "^1.0",
30-
"psr/http-message": "^1.0"
29+
"psr/http-message": "^1.0",
30+
"symfony/string": "^5.4|^6.0"
3131
},
3232
"require-dev": {
3333
"friendsofphp/php-cs-fixer": "^3.0",

docs/.vuepress/components/UrlHelper.vue

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<p>Use this helper to generate the possible fixtures for your own URL.</p>
3+
<p>Use this helper to generate the possible fixtures for your own URL. Please note this is a simple JavaScript port and it will not be 100% accurate for special or accented characters.</p>
44
<h4><label for="url">URL</label></h4>
55
<input class="input" type="text" id="url" placeholder="http://example.com/api/comments?query=json&order=id" v-model="url"/>
66
<h4><label for="method">Method</label></h4>
@@ -75,7 +75,7 @@
7575
'ŏ', 'ο', '', '', '', '', '', '', '', 'ό',
7676
'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', '', '', '',
7777
'ö'],
78-
'p' : ['п', 'π', '', '', 'پ', ''],
78+
'p' : ['п', 'π', '', '', 'پ', '', 'ƥ'],
7979
'q' : ['', ''],
8080
'r' : ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', '', ''],
8181
's' : ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', '',
@@ -253,27 +253,20 @@
253253
.map(param => {
254254
return param.replace(/[\\/?:*"><|]/g, REPLACEMENT);
255255
})
256-
// toAscii
256+
// folded + ascii
257257
.map(param => {
258258
Object.keys(CHARS).forEach(key => {
259259
param = param.replace(new RegExp(`[${CHARS[key].join('')}]`, 'g'), key);
260260
});
261-
262-
return param.replace(/[^\x20-\x7E]/gu, '');
263-
})
264-
// delimit
265-
.map(param => {
266-
return param.replace(/\B([A-Z])/g, '-$1')
267-
.toLowerCase()
268-
.replace(/[-_\s]+/g, REPLACEMENT);
261+
return param.toLowerCase().replace(/[^\x20-\x7E]/gu, '');
269262
})
270-
// removeLeft
263+
// replaceMatches
271264
.map(param => {
272-
return param.replace(new RegExp(`^${REPLACEMENT}+`), '');
265+
return param.replace(/[-_\s]+/, REPLACEMENT);
273266
})
274-
// removeRight
267+
// trim
275268
.map(param => {
276-
return param.replace(new RegExp(`${REPLACEMENT}+$`), '');
269+
return param.replace(new RegExp(`^${REPLACEMENT}+|${REPLACEMENT}+$`), '');
277270
})
278271
.join('&');
279272
}

src/ResponseBuilder.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Psr\Http\Message\ResponseInterface;
99
use Psr\Http\Message\StreamFactoryInterface;
1010
use Psr\Http\Message\StreamInterface;
11-
use Stringy\Stringy;
11+
use Symfony\Component\String\UnicodeString;
1212

1313
class ResponseBuilder implements ResponseBuilderInterface
1414
{
@@ -324,11 +324,12 @@ function (string $part) {
324324
sort($parts);
325325
$query = implode('&', $parts);
326326

327-
return (string) Stringy::create(str_replace(['\\', '/', '?', ':', '*', '"', '>', '<', '|'], $replacement, $query))
328-
->toAscii()
329-
->delimit($replacement)
330-
->removeLeft($replacement)
331-
->removeRight($replacement);
327+
return (new UnicodeString(str_replace(['\\', '/', '?', ':', '*', '"', '>', '<', '|'], $replacement, $query)))
328+
->folded()
329+
->ascii()
330+
->replaceMatches('/[-_\s]+/', $replacement)
331+
->trim($replacement)
332+
->toString();
332333
}
333334

334335
/**

0 commit comments

Comments
 (0)