Skip to content

Commit

Permalink
testharness.js: Fix logic in substitute_single when `subustitutions…
Browse files Browse the repository at this point in the history
…` is undefined

The internal function `do_substitution(input)` was assuming that `substitutions` always exists or that the length of `components` would always be 1.

Fixes #46940.
  • Loading branch information
asamuzaK authored Aug 19, 2024
1 parent ddd487f commit ff5b1bc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -4408,13 +4408,20 @@
{
var substitution_re = /\$\{([^ }]*)\}/g;

function do_substitution(input) {
function do_substitution(input)
{
var components = input.split(substitution_re);
var rv = [];
for (var i = 0; i < components.length; i += 2) {
rv.push(components[i]);
if (components[i + 1]) {
rv.push(String(substitutions[components[i + 1]]));
if (components.length === 1) {
rv = components;
} else if (substitutions) {
for (var i = 0; i < components.length; i += 2) {
if (components[i]) {
rv.push(components[i]);
}
if (substitutions[components[i + 1]]) {
rv.push(String(substitutions[components[i + 1]]));
}
}
}
return rv;
Expand Down

0 comments on commit ff5b1bc

Please sign in to comment.