From: Dmitry Volyntsev Date: Thu, 1 Sep 2022 01:35:58 +0000 (-0700) Subject: Fixed String.prototype.trimEnd() with unicode string. X-Git-Tag: 0.7.8~38 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=b9aea5854bcf6f2de8f7a7f1550874e392b94be2;p=njs.git Fixed String.prototype.trimEnd() with unicode string. Previously, when the method was invoked with a string consisting of space characters and at least one of them was a Unicode space separator (code point above 127) it returned invalid string value with non-zero size but zero length. The fix is to update the size of the resulting string appropriately. This closes #569 issue on Github. --- diff --git a/src/njs_string.c b/src/njs_string.c index 83cede54..62bece0d 100644 --- a/src/njs_string.c +++ b/src/njs_string.c @@ -2849,6 +2849,7 @@ njs_string_trim(const njs_value_t *value, njs_string_prop_t *string, for ( ;; ) { if (start == prev) { + end = prev; break; } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 287ddda2..a717f02a 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -8450,6 +8450,14 @@ static njs_unit_test_t njs_test[] = { njs_str("' абв '.trimStart().trimEnd()"), njs_str("абв") }, + { njs_str("[" + " String.fromCodePoint(0x2028)," + " String.fromCodePoint(0x20, 0x2028)," + " String.fromCodePoint(0x0009, 0x20, 0x2028)," + " String.fromCodePoint(0xFEFF)," + "].every(v => v.trimEnd() == '')"), + njs_str("true") }, + { njs_str("'\\u2029abc\\uFEFF\\u2028'.trim()"), njs_str("abc") },