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

New lines are being filtered out #779

Closed
WKampel opened this issue Nov 21, 2024 · 2 comments · Fixed by #783
Closed

New lines are being filtered out #779

WKampel opened this issue Nov 21, 2024 · 2 comments · Fixed by #783
Labels
bug Something isn't working released

Comments

@WKampel
Copy link

WKampel commented Nov 21, 2024

Context

What's your version of nuqs?

^1.17.4

What framework are you using?

  • ✅ Next.js (pages router)

Which version of your framework are you using?

14.1.3

Description

New lines (such as using a textarea) are being filtered out.

Reproduction

  1. Create the nuqs state using parseAsString
  2. Add textarea using that state
const [test, setTest] = useQueryState('test', parseAsString)

<textarea value={test ?? ''}
      onChange={(e) => {
      setTest(e.target.value)
}} />
@WKampel WKampel added the bug Something isn't working label Nov 21, 2024
@franky47
Copy link
Member

franky47 commented Nov 21, 2024

Sounds like the issue could come from the URL encoding not properly taking care of invisible characters (0-31 ASCII range). Would you like to open a PR?

return (
input
// Encode existing % signs first to avoid appearing
// as an incomplete escape sequence:
.replace(/%/g, '%25')
// Note: spaces are encoded as + in RFC 3986,
// so we pre-encode existing + signs to avoid confusion
// before converting spaces to + signs.
.replace(/\+/g, '%2B')
.replace(/ /g, '+')
// Encode other URI-reserved characters
.replace(/#/g, '%23')
.replace(/&/g, '%26')
// Encode characters that break URL detection on some platforms
// and would drop the tail end of the querystring:
.replace(/"/g, '%22')
.replace(/'/g, '%27')
.replace(/`/g, '%60')
.replace(/</g, '%3C')
.replace(/>/g, '%3E')
)

Copy link

🎉 This issue has been resolved in version 2.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants