Make WordPress Core

Opened 7 years ago

Last modified 18 months ago

#41257 new defect (bug)

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

Reported by: bobbingwide's profile bobbingwide Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: I18N Keywords: has-unit-tests close
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 years ago.
Unit test case that demonstrates the unexpected results

Download all attachments as: .zip

Change History (5)

#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.

@bobbingwide
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
6 years ago

  • Keywords has-patch removed
  • Version 4.9 deleted

#4 @swissspidy
18 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.

Note: See TracTickets for help on using tickets.