[njs] Fixed encoding matching for base64url in String.bytesFrom().

Alexander Borisov alexander.borisov at nginx.com
Tue Dec 22 15:37:41 UTC 2020


details:   https://hg.nginx.org/njs/rev/92c0493b2aff
branches:  
changeset: 1584:92c0493b2aff
user:      Disconnect3d <dominik.b.czarnota at gmail.com>
date:      Tue Dec 22 13:27:01 2020 +0100
description:
Fixed encoding matching for base64url in String.bytesFrom().

This closes #363 PR on GitHub.

diffstat:

 src/njs_string.c         |  2 +-
 src/test/njs_unit_test.c |  3 +++
 2 files changed, 4 insertions(+), 1 deletions(-)

diffs (25 lines):

diff -r d8e94445f59b -r 92c0493b2aff src/njs_string.c
--- a/src/njs_string.c	Wed Dec 16 20:27:43 2020 +0000
+++ b/src/njs_string.c	Tue Dec 22 13:27:01 2020 +0100
@@ -1753,7 +1753,7 @@ njs_string_bytes_from_string(njs_vm_t *v
     } else if (enc.length == 6 && memcmp(enc.start, "base64", 6) == 0) {
         return njs_string_decode_base64(vm, &vm->retval, &str);
 
-    } else if (enc.length == 9 && memcmp(enc.start, "base64url", 6) == 0) {
+    } else if (enc.length == 9 && memcmp(enc.start, "base64url", 9) == 0) {
         return njs_string_decode_base64url(vm, &vm->retval, &str);
     }
 
diff -r d8e94445f59b -r 92c0493b2aff src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Dec 16 20:27:43 2020 +0000
+++ b/src/test/njs_unit_test.c	Tue Dec 22 13:27:01 2020 +0100
@@ -9016,6 +9016,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("String.bytesFrom('QUJDRA#', 'base64url')"),
       njs_str("ABCD") },
 
+    { njs_str("String.bytesFrom('QUJDRA#', 'base64lol')"),
+      njs_str("TypeError: Unknown encoding: \"base64lol\"") },
+
     { njs_str("encodeURI.name"),
       njs_str("encodeURI")},
 


More information about the nginx-devel mailing list