Skip to content

Confusing, possibly buggy UrlParams.setAll #5627

@samhh

Description

@samhh

What version of Effect is running?

[email protected], @effect/[email protected]

What steps can reproduce the bug?

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { UrlParams } from '@effect/platform';

describe('setAll', () => {
  it('concats, preferring elements from the second input with preservation', () => {
    const prev = UrlParams.fromInput({
      baz: 'c',
      foo: 'd',
    });

    const neww = UrlParams.fromInput({
      foo: 'a',
      bar: 'b',
    });

    assert.deepEqual(UrlParams.toRecord(UrlParams.setAll(prev, neww)), {
      foo: ['d', 'a'],
      bar: 'b',
    });
  });
});

What is the expected behavior?

The assertion result should instead be (order notwithstanding):

assert.deepEqual(UrlParams.toRecord(UrlParamsExtras.setAll(prev, neww)), {
  baz: 'c',
  foo: 'a',
  bar: 'b',
});

What do you see instead?

The above repro assertion:

assert.deepEqual(UrlParams.toRecord(UrlParams.setAll(prev, neww)), {
  foo: ['d', 'a'],
  bar: 'b',
});

Additional information

This behaviour is confusing. Take UrlParams.set for example, which overwrites a single key but leaves others alone:

assert.deepEqual(UrlParams.toRecord(UrlParams.set(prev, 'foo', 'a')), {
  baz: 'c',
  foo: 'a',
});

The test passes my expected assertion if the keys.includes predicate is negated/inverted here: https://github.com/Effect-TS/effect/blob/%40effect/platform%400.92.1/packages/platform/src/UrlParams.ts#L164

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions