Make WordPress Core

Opened 7 years ago

Closed 3 weeks ago

#41257 closed defect (bug) (wontfix)

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

Reported by: bobbingwide's profile bobbingwide Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: I18N Keywords: has-unit-tests close
Focuses: Cc:


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


Don't call translate() this way.


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

Attachments (1)

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

Download all attachments as: .zip

Change History (6)

#1 @MaximeCulea
7 years 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.

7 years ago

Unit test case that demonstrates the unexpected results

#2 @bobbingwide
7 years 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.

#3 @ocean90
7 years ago

  • Keywords has-patch removed
  • Version 4.9 deleted

#4 @swissspidy
20 months ago

  • Keywords close added

I don't think this edge case is worth handling, null simply isn't a valid argument for a function that expects a string.

#5 @swissspidy
3 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.