Skip to content

fix(query): array with empty string elements serializes with trailing equals unlike scalar empty string #394

Open

Description

@abhi-byte62

Description

In encodeQueryItem(), when a scalar empty string "" is passed, it returns encodeQueryKey(key) without an = sign:

encodeQueryItem("flag", "")
// Returns: "flag"

However, when an array containing an empty string element [""] is passed, the array mapping unconditionally formats as ${encodeQueryKey(key)}=${encodeQueryValue(_value)}, producing an = sign:

encodeQueryItem("flag", [""])
// Returns: "flag="

Minimal Reproduction

import { encodeQueryItem, stringifyQuery } from 'ufo'

console.log(encodeQueryItem('flag', ''))    // "flag"
console.log(encodeQueryItem('flag', ['']))  // "flag="

Expected Behavior

Array elements with empty string values should follow the same encoding convention or format consistently with scalar values when stringified.

Activity

  1. owenshen0907 commented on Oct 11, 2026

    @owenshen0907

    I reproduced the difference on current main and added regression tests for scalar/array empty strings, mixed values and encoded keys. I'm preparing a minimal fix for empty string array elements to use the same bare-key encoding as scalar empty strings; null/undefined array behavior stays unchanged. I checked #391: its performance change touches the same branch but retains the behavior reported here, so this fix may need rebasing if it merges first.

  2. abhi-byte62 commented on Oct 11, 2026

    @abhi-byte62
    Author

    Thanks for verifying and putting together the fix @owenshen0907! Good catch on keeping the null/undefined array behavior intact and watching out for the overlap with #391. Looking forward to the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions