Skip to content

Instantly share code, notes, and snippets.

@xeioex
Created July 8, 2025 22:47
Show Gist options
  • Save xeioex/2c1a24a1ca0e001643762853c46f115e to your computer and use it in GitHub Desktop.
Save xeioex/2c1a24a1ca0e001643762853c46f115e to your computer and use it in GitHub Desktop.
diff --git a/src/njs_string.c b/src/njs_string.c
index aae48eba..1a2b2333 100644
--- a/src/njs_string.c
+++ b/src/njs_string.c
@@ -693,11 +693,6 @@ njs_string_prototype_concat(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
size += string.size;
length += string.length;
}
-
- if (njs_slow_path(length > NJS_STRING_MAX_LENGTH)) {
- njs_range_error(vm, "invalid string length");
- return NJS_ERROR;
- }
}
p = njs_string_alloc(vm, retval, size, length);
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 5cbf5a15..eefe8d1a 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -8176,47 +8176,6 @@ static njs_unit_test_t njs_test[] =
"var a = 'abc'; a.concat('абв', s)"),
njs_str("abcабв123") },
- /* Enhanced String.prototype.concat optimization tests */
-
- { njs_str("'Hello'.concat(' ', 'World')"),
- njs_str("Hello World") },
-
- { njs_str("'Value: '.concat(42, ' and ', 3.14)"),
- njs_str("Value: 42 and 3.14") },
-
- { njs_str("'Flags: '.concat(true, ' and ', false)"),
- njs_str("Flags: true and false") },
-
- { njs_str("'Values: '.concat(null, ' and ', undefined)"),
- njs_str("Values: null and undefined") },
-
- { njs_str("'Mixed: '.concat(123, ' ', true, ' ', null, ' ', undefined)"),
- njs_str("Mixed: 123 true null undefined") },
-
- { njs_str("'Special: '.concat(NaN, ' ', Infinity, ' ', -Infinity)"),
- njs_str("Special: NaN Infinity -Infinity") },
-
- { njs_str("'Numbers: '.concat(1234567890, ' ', 0.123456789, ' ', 1.23e-10)"),
- njs_str("Numbers: 1234567890 0.123456789 1.23e-10") },
-
- { njs_str("'Object: '.concat({})"),
- njs_str("Object: [object Object]") },
-
- { njs_str("'Pi: '.concat(3.14159, ' ', 3.14159, ' ', 3.14159)"),
- njs_str("Pi: 3.14159 3.14159 3.14159") },
-
- { njs_str("''.concat(1, true, null, undefined, 'end')"),
- njs_str("1truenullundefinedend") },
-
- { njs_str("'Zero: '.concat(0, ' ', -0)"),
- njs_str("Zero: 0 0") },
-
- { njs_str("'Range: '.concat(1e-100, ' to ', 1e100)"),
- njs_str("Range: 1e-100 to 1e+100") },
-
- { njs_str("var str = 'Base'; str.concat(' ', 'Extended')"),
- njs_str("Base Extended") },
-
{ njs_str("var r = /^\\x80$/; r.source + r.source.length"),
njs_str("^\\x80$6") },
@@ -11083,6 +11042,30 @@ static njs_unit_test_t njs_test[] =
"f.apply(123, {})"),
njs_str("123") },
+ { njs_str("'Hello'.concat(' ', 'World')"),
+ njs_str("Hello World") },
+
+ { njs_str("'Value: '.concat(42, ' and ', 3.14)"),
+ njs_str("Value: 42 and 3.14") },
+
+ { njs_str("'Flags: '.concat(true, ' and ', false)"),
+ njs_str("Flags: true and false") },
+
+ { njs_str("'Values: '.concat(null, ' and ', undefined)"),
+ njs_str("Values: null and undefined") },
+
+ { njs_str("'Mixed: '.concat(123, ' ', true, ' ', null, ' ', undefined)"),
+ njs_str("Mixed: 123 true null undefined") },
+
+ { njs_str("'Special: '.concat(NaN, ' ', Infinity, ' ', -Infinity)"),
+ njs_str("Special: NaN Infinity -Infinity") },
+
+ { njs_str("'Numbers: '.concat(1234567890, ' ', 0.123456789, ' ', 1.23e-10)"),
+ njs_str("Numbers: 1234567890 0.123456789 1.23e-10") },
+
+ { njs_str("'Zero: '.concat(0, ' ', -0)"),
+ njs_str("Zero: 0 0") },
+
{ njs_str("(function(index, ...rest){ return rest[index];})"
".apply({}, [1022].concat(Array(1023).fill(1).map((v,i)=>i.toString(16))))"),
njs_str("3fe") },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment