Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer breaks the right part of URLs containing multiple ? characters #812

Closed
ealvarezk opened this issue Dec 17, 2024 · 3 comments · Fixed by #821
Closed

Serializer breaks the right part of URLs containing multiple ? characters #812

ealvarezk opened this issue Dec 17, 2024 · 3 comments · Fixed by #821

Comments

@ealvarezk
Copy link

ealvarezk commented Dec 17, 2024

Context

What's your version of nuqs?

2.2.3

What framework are you using?

  • ✅ Next.js (app router)

Which version of your framework are you using?

Relevant Packages:
  next: 14.2.20 
  react: 18.3.1
  typescript: 5.5.4

Description

When a serialize is executed with a string base parameter that have query string parameter with a string with "?", some of the string disappear

Reproduction

https://stackblitz.com/edit/vitejs-vite-wcnxdakb?file=src%2Fmain.ts

In this example you can see that we call serialize with a base parameter that have a query string with value1 that have a ? in the middle, and the result is http://localhost:3000/?value1=value&prompt=value3 that deletes part of value1 and value 2.

import { parseAsString, createSerializer } from 'nuqs';

const serialize = createSerializer({
  prompt: parseAsString,
});

const url = serialize('http://localhost:3000/?value1=value?With&value2=35435', {
  prompt: 'value3',
});

Reading you code I found the issue in line

const [path = '', search] = base.split('?')
, where base is split but only use the first two elments of the returning array and get rid of the remaining

@ealvarezk ealvarezk added the bug Something isn't working label Dec 17, 2024
@franky47 franky47 changed the title create Serializer breaks the right part of URLs containing multiple ? characters Dec 17, 2024
@franky47
Copy link
Member

Thanks for the report, sounds like it should be an easy fix, would you like to open a PR?

Copy link

🎉 This issue has been resolved in version 2.3.0-beta.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

github-actions bot commented Jan 1, 2025

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 removed this from the 🚀 Shipping next milestone Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants