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 76fa504

Browse filesBrowse files
committed
[Validator] Convert encoding to UTF-8 when needed in NotPwnedValidator
1 parent 5fe3701 commit 76fa504
Copy full SHA for 76fa504

File tree

1 file changed

+7
-1
lines changed
Filter options

1 file changed

+7
-1
lines changed

‎src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ class NotPwnedValidator extends ConstraintValidator
3131
private const RANGE_API = 'https://api.pwnedpasswords.com/range/%s';
3232

3333
private $httpClient;
34+
private $charset;
3435

35-
public function __construct(HttpClientInterface $httpClient = null)
36+
public function __construct(HttpClientInterface $httpClient = null, string $charset = 'UTF-8')
3637
{
3738
if (null === $httpClient && !class_exists(HttpClient::class)) {
3839
throw new \LogicException(sprintf('The "%s" class requires the "HttpClient" component. Try running "composer require symfony/http-client".', self::class));
3940
}
4041

4142
$this->httpClient = $httpClient ?? HttpClient::create();
43+
$this->charset = $charset;
4244
}
4345

4446
/**
@@ -61,6 +63,10 @@ public function validate($value, Constraint $constraint)
6163
return;
6264
}
6365

66+
if ('UTF-8' !== $this->charset) {
67+
$value = mb_convert_encoding($value, 'UTF-8', $this->charset);
68+
}
69+
6470
$hash = strtoupper(sha1($value));
6571
$hashPrefix = substr($hash, 0, 5);
6672
$url = sprintf(self::RANGE_API, $hashPrefix);

0 commit comments

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