Skip to content

Commit 4f9d8bc

Browse files
Merge pull request #44 from MarcinOrlowski/rb-42-change-default-encoding-options
[RB-42] change default encoding options
2 parents 864b534 + da8c2cd commit 4f9d8bc

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

CHANGES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# API Response Builder for Laravel 5 #
22

3-
43
See [compatibility docs](docs/compatibility.md) for details about backward compatibility!
54

6-
75
## CHANGE LOG ##
86

97
* @dev
8+
* [RB-42] Default value of `encoding_options` include `JSON_UNESCAPED_UNICODE` to prevent unicode escaping
109
* [RB-41] Updated documentation
1110

1211
* v3.1.0 (2017-02-28)
13-
* [RB-38] Added `encoding-options` to control data-to-json conversion.
12+
* [RB-38] Added `encoding_options` to control data-to-json conversion.
1413
* [RB-38] Added optional encoding options args to all methods accepting `data` argument
1514
* [RB-34] Added option to control ExceptionHandeler behavior on debug builds
1615
* ExceptionHandler's debug is now added as `debug` node to make it more clear where it comes from
@@ -109,3 +108,4 @@ See [compatibility docs](docs/compatibility.md) for details about backward compa
109108

110109
* v1.0.0 (2016-04-11)
111110
* Initial public release
111+

config/response_builder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@
9494
| to be returned escaped, which while technically correct (ant theoretically
9595
| transparent) might not be desired effects.
9696
|
97-
| To prevent escaping, add JSON_UNESCAPED_UNICODE:
97+
| To prevent escaping, add JSON_UNESCAPED_UNICODE (default since v3.2):
9898
| JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE
9999
|
100-
| Default value:
100+
| Laravel's value:
101101
| JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT
102102
|
103103
| See http://php.net/manual/en/function.json-encode.php for details
104104
|
105105
*/
106-
'encoding_options' => JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT,
106+
'encoding_options' => JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE,
107107

108108

109109
/*

src/ResponseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class ResponseBuilder
4040
/**
4141
* Default JSON encoding options
4242
*
43-
* 15 = JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT
43+
* 271 = JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE
4444
*
4545
* This must be as int due to const limits in PHP disallowing expressions.
4646
*/
47-
const DEFAULT_ENCODING_OPTIONS = 15;
47+
const DEFAULT_ENCODING_OPTIONS = 271;
4848

4949
/**
5050
* Reads and validates "classes" config mapping

tests/InternalsTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function testMake_InvalidEncodingOptions()
6969
}
7070

7171
/**
72-
* Tests if JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT matches const value of DEFAULT_ENODING_OPTIONS
72+
* Tests if dist's config detaults matches ResponseBuilder::DEFAULT_ENODING_OPTIONS
7373
*
7474
* @return void
7575
*/
7676
public function testDefaultEncodingOptionValue()
7777
{
78-
$this->assertEquals(JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT, ResponseBuilder::DEFAULT_ENCODING_OPTIONS);
78+
$config_defaults = \Config::get('response_builder.encoding_options');
79+
$this->assertEquals($config_defaults, ResponseBuilder::DEFAULT_ENCODING_OPTIONS);
7980
}
8081

8182
/**
@@ -87,7 +88,7 @@ public function testMake_DefaultEncodingOptions()
8788
{
8889
// source data
8990
$test_string = 'ąćę';
90-
$test_string_escaped = $this->escape8($test_string);
91+
// $test_string_escaped = $this->escape8($test_string);
9192
$data = ['test' => $test_string];
9293

9394
// fallback defaults in action

0 commit comments

Comments
 (0)