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

Message parser doesn't handle CRLF linebreaks #1847

Open
rafalp opened this issue Jan 25, 2025 · 2 comments
Open

Message parser doesn't handle CRLF linebreaks #1847

rafalp opened this issue Jan 25, 2025 · 2 comments
Assignees
Labels
area: backend This issue involves Python, Django or dependency (eg. database) bug feature: parser Parser converts markdown/bbcode strings into other forms

Comments

@rafalp
Copy link
Owner

rafalp commented Jan 25, 2025

Markup:

Lorem ipsum

Dolor met

HTML result:

<p>Lorem Ipsum<br /><br />Dolor met</p>

Expected result:

<p>Lorem Ipsum</p>
<p>Dolor met</p>

This happens because parser expects LF (\n) input and browsers send CRLF (\r\n)

We can fix this in two steps:

  • Run .replace("\r\n", "\n").replace("\r", "\n") to normalize newlines before we send the string deeper into parser.
  • Do the .replace("\n", "\r\n") in reverse when rendering AST back to HTML/plaintext/etc.
  • Replace \n with \r\n on formatting help page.
@rafalp rafalp added this to the Next feature release milestone Jan 25, 2025
@rafalp rafalp added bug area: backend This issue involves Python, Django or dependency (eg. database) critical feature: parser Parser converts markdown/bbcode strings into other forms labels Jan 25, 2025
@rafalp rafalp self-assigned this Jan 25, 2025
@rafalp rafalp changed the title Double linebreak no longer breaks text into two paragraphs Message parser doesn't handle CRLF linebreaks Jan 26, 2025
@rafalp
Copy link
Owner Author

rafalp commented Jan 26, 2025

We should also check all .join(”\n”) in codebase and change them to CRLF as part of this fix.

@raydeal
Copy link
Contributor

raydeal commented Feb 1, 2025

Hi, I can work on this ticket.

@rafalp rafalp assigned raydeal and unassigned rafalp Feb 1, 2025
@rafalp rafalp removed the help wanted label Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend This issue involves Python, Django or dependency (eg. database) bug feature: parser Parser converts markdown/bbcode strings into other forms
Projects
None yet
Development

No branches or pull requests

2 participants