Skip to content

Commit

Permalink
MappingFailedException: do not escape slash
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Oct 6, 2023
1 parent 1ca8f19 commit c287a27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Runtime/Exception/MappingFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
use function substr;
use const JSON_PRESERVE_ZERO_FRACTION;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;

class MappingFailedException extends RuntimeException
{

private const JSON_ENCODE_OPTIONS = JSON_PRESERVE_ZERO_FRACTION | JSON_THROW_ON_ERROR;
private const JSON_ENCODE_OPTIONS = JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR;
private const MAX_STRING_LENGTH = 40;

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Runtime/Exception/MappingFailedExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public static function provideMessagesData(): iterable
'Failed to map data at path /foo: Expected int, got "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" (truncated)',
];

yield 'string with slash' => [
MappingFailedException::incorrectValue('foo/bar', ['foo'], 'int'),
'Failed to map data at path /foo: Expected int, got "foo/bar"',
];

yield 'string with control characters' => [
MappingFailedException::incorrectValue("foo\x00bar", ['foo'], 'int'),
'Failed to map data at path /foo: Expected int, got string',
Expand Down

0 comments on commit c287a27

Please sign in to comment.