Fixed njs_string_truncate() function for non-byte strings.
diff --git a/src/njs_fs.c b/src/njs_fs.c
index 4f7f051..fad0678 100644
--- a/src/njs_fs.c
+++ b/src/njs_fs.c
@@ -262,7 +262,7 @@
 
         if (njs_slow_path(data.length < size)) {
             /* Pseudo-files may return less data than declared by st_size. */
-            njs_string_truncate(&retval, data.length);
+            njs_string_truncate(&retval, data.length, length);
         }
 
         size = data.length;
diff --git a/src/njs_string.c b/src/njs_string.c
index 9aa24a2..6207288 100644
--- a/src/njs_string.c
+++ b/src/njs_string.c
@@ -172,30 +172,33 @@
 
 
 void
-njs_string_truncate(njs_value_t *value, uint32_t size)
+njs_string_truncate(njs_value_t *value, uint32_t size, uint32_t length)
 {
-    u_char  *dst, *src;
+    u_char    *dst, *src;
+    uint32_t  n;
 
     if (size <= NJS_STRING_SHORT) {
-        if (value->short_string.size != NJS_STRING_LONG) {
-            value->short_string.size = size;
-
-        } else {
-            value->short_string.size = size;
+        if (value->short_string.size == NJS_STRING_LONG) {
             dst = value->short_string.start;
             src = value->long_string.data->start;
 
-            while (size != 0) {
+            n = size;
+
+            while (n != 0) {
                 /* The maximum size is just 14 bytes. */
                 njs_pragma_loop_disable_vectorization;
 
                 *dst++ = *src++;
-                size--;
+                n--;
             }
         }
 
+        value->short_string.size = size;
+        value->short_string.length = length;
+
     } else {
         value->long_string.size = size;
+        value->long_string.data->length = length;
     }
 }
 
@@ -1708,7 +1711,7 @@
     }
 
     if (njs_slow_path((size_t) (p - dst) != (len / 2))) {
-        njs_string_truncate(value, p - dst);
+        njs_string_truncate(value, p - dst, 0);
     }
 
     return NJS_OK;
@@ -1825,7 +1828,7 @@
     }
 
     if (njs_slow_path((size_t) (d - dst) != dst_len)) {
-        njs_string_truncate(value, d - dst);
+        njs_string_truncate(value, d - dst, 0);
     }
 
     return NJS_OK;
diff --git a/src/njs_string.h b/src/njs_string.h
index da300a4..a1154cb 100644
--- a/src/njs_string.h
+++ b/src/njs_string.h
@@ -173,7 +173,7 @@
     const njs_str_t *src);
 njs_int_t njs_string_decode_base64url(njs_vm_t *vm, njs_value_t *value,
     const njs_str_t *src);
-void njs_string_truncate(njs_value_t *value, uint32_t size);
+void njs_string_truncate(njs_value_t *value, uint32_t size, uint32_t length);
 void njs_string_copy(njs_value_t *dst, njs_value_t *src);
 njs_int_t njs_string_validate(njs_vm_t *vm, njs_string_prop_t *string,
     njs_value_t *value);