Template talk:Replace

Latest comment: 3 months ago by Od1n in topic Edit request 19 August 2024

"Template:Str rep all" listed at Redirects for discussion

edit

  A discussion is taking place to address the redirect Template:Str rep all. The discussion will occur at Wikipedia:Redirects for discussion/Log/2021 April 26#Template:Str rep all until a consensus is reached, and readers of this page are welcome to contribute to the discussion. User:GKFXtalk 07:16, 26 April 2021 (UTC)Reply

Edit request 19 August 2024

edit

There is currently a code mistake in Module:String.replace(): if provided with plain = '' (argument present, empty string), the "plain mode" is unexpectedly set to "false", instead of the default "true".

To better understand the issue, see this diff: 1123206365.

The template {{Replace}} is consequently affected: if doing {{replace|...|plain=}}, the "plain mode" is also unexpectedly set to "false", instead of the default "true".

Therefore, I am suggesting the following code, that replaces {{{plain|true}}} with {{{#if:{{{plain|}}}|{{{plain}}}|true}}. In addition to being better practice, it will "detach" the template behavior from the module behavior, so that the template works as expected (i.e. empty parameter gives default mode "true"), whether the module remains as currently, or gets fixed in the future.

<includeonly>{{safesubst:#invoke:String|replace|source={{{1}}}|{{{2}}}|{{{3}}}|plain={{safesubst:#if:{{{plain|}}}|{{{plain}}}|true}}|count={{{count|}}}}}</includeonly><noinclude>
{{documentation}}
</noinclude>

I have checked in the whole wiki, and there is no {{replace|...|plain=}} use currently. So the change is completely safe.

Finally, note that if the module is fixed in the future, it would be possible to simplify the template code to |plain={{{plain|}}}.

Od1n (talk) 08:32, 19 August 2024 (UTC)Reply

I have just noticed that Module:String.find() is affected by the exact same issue. And I have already noticed a consequently affected template: {{If string}} (which is very rarely used), and another one: {{In string}}. These templates currently use String.find() by default in "plain = false" mode (because of the module bug), and fixing the module would change the default mode of these templates to "true" if they are not modified adequately.
By "detaching" behaviors (as in the current edit request) and leveraging the powerful in-wiki search engine (that allows regex searching) to examinate the existing uses, fixing all of that is quite simple actually.
(edit: just noticed that Module:String.count() ({{string count}}, {{str count}}…) is affected by the same issue)
Od1n (talk) 08:45, 19 August 2024 (UTC)Reply
  Done * Pppery * it has begun... 20:57, 19 August 2024 (UTC)Reply
Thanks. A few other edit requests should be following up, to fix the situation step by step.
As a reminder, the "plain mode" may also be specified as an unnamed parameter. Fortuitously, it is very unlikely that someone has specified a "plain mode" as a both unnamed and empty parameter. However, when fixing the module, we should consider that the parameter value may have spaces.
Od1n (talk) 01:38, 20 August 2024 (UTC)Reply