fix: jv_dump_string_trunc should not break unicode characters (#3249)
This commit is contained in:
1 parent
fa6a2ff688
commit
64bd8ba374
2 files changed
+23
-9
No files matched your search
+10
-9
@@ -381,16 +381,17 @@ jv jv_dump_string(jv x, int flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *jv_dump_string_trunc(jv x, char *outbuf, size_t bufsize) {
|
char *jv_dump_string_trunc(jv x, char *outbuf, size_t bufsize) {
|
||||||
x = jv_dump_string(x,0);
|
x = jv_dump_string(x, 0);
|
||||||
const char* p = jv_string_value(x);
|
const char *str = jv_string_value(x);
|
||||||
const size_t len = strlen(p);
|
const size_t len = strlen(str);
|
||||||
strncpy(outbuf, p, bufsize);
|
strncpy(outbuf, str, bufsize);
|
||||||
outbuf[bufsize - 1] = 0;
|
|
||||||
if (len > bufsize - 1 && bufsize >= 4) {
|
if (len > bufsize - 1 && bufsize >= 4) {
|
||||||
// Indicate truncation with '...'
|
// Indicate truncation with '...' without breaking UTF-8.
|
||||||
outbuf[bufsize - 2]='.';
|
const char *s = jvp_utf8_backtrack(outbuf + bufsize - 4, outbuf, NULL);
|
||||||
outbuf[bufsize - 3]='.';
|
if (s) bufsize = s + 4 - outbuf;
|
||||||
outbuf[bufsize - 4]='.';
|
strcpy(outbuf + bufsize - 4, "...");
|
||||||
|
} else {
|
||||||
|
outbuf[bufsize - 1] = '\0';
|
||||||
}
|
}
|
||||||
jv_free(x);
|
jv_free(x);
|
||||||
return outbuf;
|
return outbuf;
|
||||||
|
|||||||
@@ -1788,6 +1788,19 @@ try -. catch .
|
|||||||
"very-long-string"
|
"very-long-string"
|
||||||
"string (\"very-long-...) cannot be negated"
|
"string (\"very-long-...) cannot be negated"
|
||||||
|
|
||||||
|
try (.-.) catch .
|
||||||
|
"very-long-string"
|
||||||
|
"string (\"very-long-...) and string (\"very-long-...) cannot be subtracted"
|
||||||
|
|
||||||
|
"x" * range(0; 12; 2) + "☆" * 5 | try -. catch .
|
||||||
|
null
|
||||||
|
"string (\"☆☆☆...) cannot be negated"
|
||||||
|
"string (\"xx☆☆...) cannot be negated"
|
||||||
|
"string (\"xxxx☆☆...) cannot be negated"
|
||||||
|
"string (\"xxxxxx☆...) cannot be negated"
|
||||||
|
"string (\"xxxxxxxx...) cannot be negated"
|
||||||
|
"string (\"xxxxxxxxxx...) cannot be negated"
|
||||||
|
|
||||||
join(",")
|
join(",")
|
||||||
["1",2,true,false,3.4]
|
["1",2,true,false,3.4]
|
||||||
"1,2,true,false,3.4"
|
"1,2,true,false,3.4"
|
||||||
|
|||||||
Reference in new issue
Block a user