Skip to content

Don't escape carriage return#78

Merged
hishamco merged 5 commits intomainfrom
hishamco/carriage-return
Apr 26, 2026
Merged

Don't escape carriage return#78
hishamco merged 5 commits intomainfrom
hishamco/carriage-return

Conversation

@hishamco
Copy link
Copy Markdown
Member

Related to #76

@Skrypt we could ignore \r instead of throwing an exception

@Skrypt
Copy link
Copy Markdown
Contributor

Skrypt commented Dec 15, 2023

That would not work because the string would still be there in Orchard Core?

It would try to still find a string that has that \r\n

@S["Something\r\n"]

If you ignore it then that string will never match any translated PO string.

@hishamco
Copy link
Copy Markdown
Member Author

That would not work because the string would still be there in Orchard Core?

Could you please elaborate?

It would try to still find a string that has that \r\n

There's no string in OC has \r\n

@Skrypt
Copy link
Copy Markdown
Contributor

Skrypt commented Dec 19, 2023

OC or not. When you use the POExtractor it will extract strings in code.
If you escape \r­ from the POExtractor then it will create a string in the resulting PO file that doesn't contain it.
Which means that it will never match anything from your code.

@t["Something \r\n"] --> in your C# code will become

msgid "Something \n"

Then when you try to load translations it will try to find a matching string for "Something \r\n" still which will result in that string to never be translated unless you remove the "\r" from your code. Here, you need to warn the user that you found a "\r" in the code and that you escaped it else the user will never know about it.

@hishamco
Copy link
Copy Markdown
Member Author

We might log a warning when the user is using \r only

# Conflicts:
#	src/OrchardCoreContrib.PoExtractor/PoWriter.cs
#	test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs
@hishamco
Copy link
Copy Markdown
Member Author

@Skrypt, anything to add here, or shall I merge coz I need to bump the package

@hishamco
Copy link
Copy Markdown
Member Author

I asked Copilot for the last review before merge coz I need to bump the version tonight or tomorrow

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates PO/POT string escaping to address issue #76 where CRLF (\r\n) sequences in source strings can end up as real newlines in generated msgid values.

Changes:

  • Adjusted PoWriter.Escape to escape CRLF as \\r\\n (instead of escaping \r independently).
  • Added a new unit test asserting carriage return handling in PoWriter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/OrchardCoreContrib.PoExtractor/PoWriter.cs Changes escaping behavior for CRLF/newlines in generated PO output.
test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs Adds coverage for carriage return behavior in generated msgid.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/OrchardCoreContrib.PoExtractor/PoWriter.cs
Comment on lines +57 to +69
Text = "Orchard\rCore"
};

// Act
using (var writer = new PoWriter(_stream))
{
writer.WriteRecord(localizableString);
}

// Assert
var result = ReadPoStream();
Assert.Equal("msgid \"Orchard\rCore\"", result[0]);
Assert.Equal("msgstr \"\"", result[1]);
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test asserts that a standalone carriage return is preserved in the emitted msgid (it expects an actual \r control character in the output). A raw \r inside a PO line is typically undesirable and can lead to invalid or hard-to-read .pot files. If the intent is to fix \r\n handling (issue #76), consider adjusting this test to cover CRLF specifically, or to verify that standalone \r is normalized (removed) or escaped instead of being written verbatim.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test in commit 9c494b0: renamed it to WriteRecord_ShouldEscape_CarriageReturn and changed the assertion to verify that a standalone \r is escaped to \\r in the PO output, rather than being written verbatim.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hishamco hishamco merged commit 58036b5 into main Apr 26, 2026
1 check passed
@hishamco hishamco deleted the hishamco/carriage-return branch April 26, 2026 04:03
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.

4 participants