Make WordPress Core

Opened 15 months ago

Last modified 15 months ago

#57981 new defect (bug)

Export .po files error of untranslated strings starting or ending with new lines (\n)

Reported by: pedromendonca's profile pedromendonca Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.8
Component: I18N Keywords: has-patch
Focuses: Cc:

Description

As found while dealing with GlotPress [see GitHub issue]https://github.com/GlotPress/GlotPress/issues/1594, there is a bug on the method export_entry() of class PO of core.

The PO method match_begin_and_end_newlines() has an early check for $translation, early returns the variable without changing nothing if the variable is '' (empty).

As match_begin_and_end_newlines() is only early returning for '' (empty) values, fails and actually adds new lines on null translations, which is wrong, and produces the undesired effect as seen in the GlotPress export error mentioned above.

The problem is that when the translation don't exist, it's set to null, not '' (empty). But export_entry() sends to match_begin_and_end_newlines() either '' (empty) in case $entry->translations is empty, or, of the translations array do exist, each one might have null values, which is the correct default behavior.

So, for consistency probably match_begin_and_end_newlines() should only check for null values to earlier return, and the export_entry() should only sends null or non-empty strings in case there is an actual translation.

Change History (5)

This ticket was mentioned in PR #4260 on WordPress/wordpress-develop by @pedromendonca.


15 months ago
#1

  • Keywords has-patch added

Make export_entry() only send $translation to match_begin_and_end_newlines(), either null if don't exist, or non-empty string if exist. And make match_begin_and_end_newlines() early return for nullvalues instead of '' (empty), which is wrong and gives wrong exports as reported in https://github.com/GlotPress/GlotPress/issues/1594

Trac ticket: https://core.trac.wordpress.org/ticket/57981

#2 @pedromendonca
15 months ago

  • Keywords has-patch removed

Another options to what I've suggested in the PR:

  • Leave the export_entry() untouched and make sure the match_begin_and_end_newlines() checks both for null and '' (empty) values.
  • Use strval( $translation ) to make sure that only strings are sent to match_begin_and_end_newlines(), cleaning up any null $translation values.

But I think it wouldn't be as simpler as I've made in the PR.

Thoughts on this would be appreciated.

Last edited 15 months ago by pedromendonca (previous) (diff)

@pedromendonca commented on PR #4260:


15 months ago
#3

@mukeshpanchal27 another options to what I've suggested in the PR:

  • Leave the export_entry() untouched and make sure the match_begin_and_end_newlines() checks both for null and '' (empty) values.
  • Use strval( $translation ) to make sure that only strings are sent to match_begin_and_end_newlines(), cleaning up any null $translation values.

But I think it wouldn't be as simpler as I've made in the PR.

Thoughts on this would be appreciated.

#4 @mukesh27
15 months ago

  • Keywords has-patch added
  • Version trunk deleted

#5 @costdev
15 months ago

  • Version set to 2.8

Lines affected by PR 4260 appear to have been introduced in:

Updating the ticket's Version property to 2.8 to note the earliest version that the problematic code was introduced.

Note: See TracTickets for help on using tickets.