Skip to content

bug(core): buildUrlParams creates double ampersands for array parameters #8270

@maniktyagi04

Description

@maniktyagi04

Bug Report

Description

The buildUrlParams function in core/src/core-plugins.ts has two bugs:

  1. Array parameters produce double ampersands (&&) in the output
  2. Uses deprecated substr() method

Root Cause

Bug 1 - Missing assignment (line 336):

value.forEach((str) => {
  encodedValue = shouldEncode ? encodeURIComponent(str) : str;
  item += `${key}=${encodedValue}&`;
});
// last character will always be "&" so slice it off
item.slice(0, -1);  // ❌ Result not assigned!

Bug 2 - Deprecated method (line 346):

return output.substr(1);  // ❌ substr is deprecated

Expected Behavior

buildUrlParams({ tags: ['javascript', 'typescript'], key: 'value' })
// Should return: "tags=javascript&tags=typescript&key=value"

Actual Behavior

buildUrlParams({ tags: ['javascript', 'typescript'], key: 'value' })
// Returns: "tags=javascript&tags=typescript&&key=value"  // Note the &&

Proposed Fix

Fix 1 - Assign the slice result:

item = item.slice(0, -1);

Fix 2 - Replace deprecated substr:

return output.substring(1);

Impact

  • Severity: Medium (malformed URL parameters)
  • Affected: HTTP plugin when using array parameters
  • Breaking: No

Additional Context

I have a PR ready with both fixes and test cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions