WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#41257 new defect (bug)

translate( null, "domain" ) returns translation of "0" rather than null

Reported by: bobbingwide Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: trunk
Component: I18N Keywords: has-unit-tests has-patch
Focuses: Cc:

Description

This could be a case of garbage in = garbage out but I noticed that calling

translate( null, "domain" ) or translate( "", "domain" ) produces an unexpected result when

  • the text domain for "domain" is loaded
  • and it contains a translation for "0".

Expected output

null or null string

Actual output

translation of the "0" string

Workaround

Don't call translate() this way.

Question

Could/should there be a unit test to confirm what should happen?

Attachments (1)

41257.patch (835 bytes) - added by bobbingwide 7 weeks ago.
Unit test case that demonstrates the unexpected results

Download all attachments as: .zip

Change History (3)

#1 @MaximeCulea
7 weeks ago

I am wondering if translate( null, "domain" ) could solve here your problem.
Because it seems legit for me that if the first arg is empty ( null, zero, empty string, etc), the translation "fails".
Moreover, I see that first arg is specified like this :

string $text Text to translate.

@bobbingwide
7 weeks ago

Unit test case that demonstrates the unexpected results

#2 @bobbingwide
7 weeks ago

  • Keywords has-unit-tests has-patch added
  • Severity changed from normal to minor

@MaximeCulea Not sure what you mean by your first sentence.

I've added a unit test case that demonstrates the unexpected results, thereby confirming the current edge case behaviour.
If the logic in translate() is changed so that it returns different values then the test will fail.

Note: See TracTickets for help on using tickets.