]> git.kaiwu.me - njs.git/commitdiff
Fixed String.prototype.trimEnd() with unicode string.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 1 Sep 2022 01:35:58 +0000 (18:35 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 1 Sep 2022 01:35:58 +0000 (18:35 -0700)
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.

src/njs_string.c
src/test/njs_unit_test.c

index 83cede548f9e28ffc53a7310d57e3367642fc513..62bece0de83a13d6e543976311c23937b3503d0f 100644 (file)
@@ -2849,6 +2849,7 @@ njs_string_trim(const njs_value_t *value, njs_string_prop_t *string,
 
             for ( ;; ) {
                 if (start == prev) {
+                    end = prev;
                     break;
                 }
 
index 287ddda2d5d173282211bc0a9f45830ff46b8dbb..a717f02a875298ef09481fc9c41638a53ee2fcad 100644 (file)
@@ -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") },