-
-
Save LawnGnome/7735daabc56fb38eb511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ext/json/json.c b/ext/json/json.c | |
index fc1fcb7..853611e 100644 | |
--- a/ext/json/json.c | |
+++ b/ext/json/json.c | |
@@ -96,6 +96,7 @@ static PHP_MINIT_FUNCTION(json) | |
REGISTER_LONG_CONSTANT("JSON_UNESCAPED_SLASHES", PHP_JSON_UNESCAPED_SLASHES, CONST_CS | CONST_PERSISTENT); | |
REGISTER_LONG_CONSTANT("JSON_PRETTY_PRINT", PHP_JSON_PRETTY_PRINT, CONST_CS | CONST_PERSISTENT); | |
REGISTER_LONG_CONSTANT("JSON_UNESCAPED_UNICODE", PHP_JSON_UNESCAPED_UNICODE, CONST_CS | CONST_PERSISTENT); | |
+ REGISTER_LONG_CONSTANT("JSON_PARTIAL_OUTPUT_ON_ERROR", PHP_JSON_PARTIAL_OUTPUT_ON_ERROR, CONST_CS | CONST_PERSISTENT); | |
REGISTER_LONG_CONSTANT("JSON_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS | CONST_PERSISTENT); | |
REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, CONST_CS | CONST_PERSISTENT); | |
@@ -389,9 +390,7 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR | |
} | |
if (ulen < 0) { | |
JSON_G(error_code) = PHP_JSON_ERROR_UTF8; | |
- if (!PG(display_errors)) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UTF-8 sequence in argument"); | |
- } | |
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UTF-8 sequence in argument"); | |
smart_str_appendl(buf, "null", 4); | |
} else { | |
smart_str_appendl(buf, "\"\"", 2); | |
@@ -689,7 +688,11 @@ static PHP_FUNCTION(json_encode) | |
php_json_encode(&buf, parameter, options TSRMLS_CC); | |
- ZVAL_STRINGL(return_value, buf.c, buf.len, 1); | |
+ if (JSON_G(error_code) != PHP_JSON_ERROR_NONE && options ^ PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { | |
+ ZVAL_FALSE(return_value); | |
+ } else { | |
+ ZVAL_STRINGL(return_value, buf.c, buf.len, 1); | |
+ } | |
smart_str_free(&buf); | |
} | |
diff --git a/ext/json/php_json.h b/ext/json/php_json.h | |
index ef3e4b5..20426c0 100644 | |
--- a/ext/json/php_json.h | |
+++ b/ext/json/php_json.h | |
@@ -63,6 +63,7 @@ extern zend_class_entry *php_json_serializable_ce; | |
#define PHP_JSON_UNESCAPED_SLASHES (1<<6) | |
#define PHP_JSON_PRETTY_PRINT (1<<7) | |
#define PHP_JSON_UNESCAPED_UNICODE (1<<8) | |
+#define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9) | |
/* Internal flags */ | |
#define PHP_JSON_OUTPUT_ARRAY 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment