Skip to content

fix: do not escape newlines #3320

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

dword-design
Copy link

@dword-design dword-design commented Apr 21, 2025

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

πŸ“š Description

Currently newlines are escaped when putting strings as fields into @nuxt/content. That means that the newlines that are returned from e.g. queryCollection aren't real newlines but slashes followed by an n char. This is clearly visible when converting the field value to JSON, then the output looks something like line1\\nline2 instead of line1\nline2. Concretely this breaks my nuxt-content-body-html module that generates a html for @nuxt/content posts. In the final result e.g. in code blocks, there will just be \n strings instead of real line breaks.

I think there are two issues:

  1. The newlines are escaped when generating the inserts
  2. Actual newlines are used to split the decompressed dump on client side

I've fixed them by keeping the newlines in the queries and using JSON.stringify and JSON.parse to communicate the dump between server and client instead of spliting by \n.

I haven't fixed the tests yet since I don't know yet if the PR gets merged.

Reproduction

https://codesandbox.io/p/devbox/j4yj8k

Copy link

pkg-pr-new bot commented Apr 21, 2025

npm i https://pkg.pr.new/@nuxt/content@3320

commit: 836bbdd

@dword-design dword-design changed the title do not escape newlines fix: do not escape newlines Apr 21, 2025
@farnabaz
Copy link
Member

What issue does this PR aim to fix? Could you provide a reproduction sample?

@dword-design
Copy link
Author

@farnabaz I added more details and a reproduction link.

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