Skip to content

[functions] URL encode cache tags#14749

Merged
kldavis4 merged 4 commits intomainfrom
kd/01-27-_functions_url_encode_cache_tags
Jan 27, 2026
Merged

[functions] URL encode cache tags#14749
kldavis4 merged 4 commits intomainfrom
kd/01-27-_functions_url_encode_cache_tags

Conversation

@kldavis4
Copy link
Copy Markdown
Contributor

@kldavis4 kldavis4 commented Jan 27, 2026

TL;DR

URL encode cache tags to properly handle special characters.

What changed?

  • Added URL encoding for cache tags using encodeURIComponent before they're sent to the cache API
  • Created helper functions encodeTags, encodeTag, and encodeOptions to handle encoding
  • Updated the cache wrapper to use these encoding functions when setting cache entries or expiring tags
  • Added unit tests to verify proper encoding of tags with spaces, commas, ampersands, and other special characters

How to test?

  1. Create cache entries with tags containing special characters:

    await cache.set('key', 'value', {
      tags: ['tag with spaces', 'tag&special=chars', 'tag,with,commas']
    });
  2. Expire tags with special characters:

    await cache.expireTag('tag&special');
    await cache.expireTag(['tag one', 'tag&two']);
  3. Verify that the tags are properly encoded when sent to the cache API

Why make this change?

Previously, cache tags containing special characters (spaces, commas, ampersands, etc.) were not properly handled when setting cache entries or expiring tags. This could lead to unexpected behavior when using tags like "my tag" or "category,item". By URL encoding the tags, we ensure they are correctly processed by the cache API, improving reliability and preventing potential issues with tag-based cache operations.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: e2c8d18

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@vercel/functions Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kldavis4 kldavis4 marked this pull request as ready for review January 27, 2026 15:23
@kldavis4 kldavis4 requested review from a team as code owners January 27, 2026 15:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

📦 CLI Tarball Ready

The Vercel CLI tarball for this PR is now available!

Quick Test

You can test this PR's CLI directly by running:

npx https://vercel-nsotvrlsp.vercel.sh/tarballs/vercel.tgz --help

Use in vercel.json

To use this CLI version in your project builds, add to your vercel.json:

{
  "build": {
    "env": {
      "VERCEL_CLI_VERSION": "vercel@https://vercel-nsotvrlsp.vercel.sh/tarballs/vercel.tgz"
    }
  }
}

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

🧪 Unit Test Strategy

Comparing: 5136665e2c8d18 (view diff)

Strategy: Affected packages only

✅ Only testing packages that have been modified or depend on modified packages.

Affected packages - 11 (27%)
  1. @vercel/edge
  2. @vercel/elysia
  3. @vercel/express
  4. @vercel/fastify
  5. @vercel/functions
  6. @vercel/h3
  7. @vercel/hono
  8. @vercel/koa
  9. @vercel/nestjs
  10. @vercel/node
  11. vercel
Unaffected packages - 30 (73%)
  1. @vercel-internals/get-package-json
  2. @vercel/backends
  3. @vercel/build-utils
  4. @vercel/cervel
  5. @vercel/cli-auth
  6. @vercel/client
  7. @vercel/config
  8. @vercel/detect-agent
  9. @vercel/error-utils
  10. @vercel/firewall
  11. @vercel/frameworks
  12. @vercel/fs-detectors
  13. @vercel/gatsby-plugin-vercel-builder
  14. @vercel/go
  15. @vercel/hydrogen
  16. @vercel/introspection
  17. @vercel/next
  18. @vercel/oidc
  19. @vercel/oidc-aws-credentials-provider
  20. @vercel/python
  21. @vercel/python-analysis
  22. @vercel/redwood
  23. @vercel/related-projects
  24. @vercel/remix-builder
  25. @vercel/routing-utils
  26. @vercel/ruby
  27. @vercel/rust
  28. @vercel/static-build
  29. @vercel/static-config
  30. examples

Results

  • Unit tests: Only affected packages will run unit tests
  • E2E tests: Handled separately (Version Packages PRs or run-e2e-tests label)
  • Type checks: Only affected packages will run type checks

This comment is automatically generated based on the affected testing strategy

Co-authored-by: Tom Lienard <tom.lienrd@gmail.com>
@kldavis4 kldavis4 merged commit 81336d6 into main Jan 27, 2026
124 checks passed
@kldavis4 kldavis4 deleted the kd/01-27-_functions_url_encode_cache_tags branch January 27, 2026 16:44
brookemosby pushed a commit that referenced this pull request Jan 27, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/functions@3.4.0

### Minor Changes

- Fix cache tags to be URL encoded before being sent to the cache API.
Tags containing special characters (spaces, commas, ampersands, etc.)
are now properly encoded using `encodeURIComponent`. This
([#14749](#14749))
ensures tags like `"my tag"` or `"category,item"` are correctly handled
when setting cache entries or expiring tags.

## vercel@50.7.1

### Patch Changes

- Prebuilt Bulk Redirects
([#14627](#14627))

-   Updated dependencies \[]:
    -   @vercel/node@5.5.28

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
styfle added a commit that referenced this pull request Feb 23, 2026
styfle added a commit that referenced this pull request Feb 24, 2026
Reverts #14749 since this caused a regression when using
`:` and other characters in tags.

The expected behavior is that commas split into multiple tags.

<!-- VADE_RISK_START -->
> [!WARNING]
> High Risk Change
>
> Revert removes URL encoding of cache tags, which could allow special
characters like commas to be interpreted as tag delimiters, potentially
affecting cache invalidation behavior.
> 
> - Removes encodeURIComponent from cache tags in set() and expireTag()
> - Tags with special characters (commas, spaces, ampersands) now passed
through unencoded
> - Removes associated URL encoding tests
>
> <sup>Risk assessment for [commit
83d1d76](https://github.com/vercel/vercel/commit/83d1d7601b8ecaf69a01e90cdd612dcd5aeaea30).</sup>
<!-- VADE_RISK_END -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants