ParserFunctions/5678
From Meta
- (fixed)
The parser functions can corrupt the literal {{{ par }}} for undefined parameters, replacing it by what its value would be inside a template, if the parser function expression were interpreted as the template call. This effect is not recursive, except in an unclear way in the case of nested parser functions, see below.
- Defined parameters are not affected.
- Parameter defaults are affected in the case of substitution of the parser function only, see Help:Substitution#Corrupted default value.
- This oddity affects also other predefined templates, example:
{{ plural: 0 | 1 | 5678 {{{2}}}}} gives 5678 {{{2}}}
A condensed variant of the table posted on Talk:ParserFunctions, see also mediazilla:5678. Test cases for the "else" anomaly clobbering the second parameter and comparisons with ifdef and ifndef added, subst test case removed (known to fail with ifndef or qif). As the 3rd column is correct, the problem is fixed if the 2nd column shows the same result.
Contents |
[edit] #if: table
| Code | Result | ifdef |
|---|---|---|
{{#if: {{{tst}}} | -1- {{{1}}} }}
|
-1- {{{1}}} | -1- {{{1}}} |
{{#if: {{{tst}}} | -1b- abc={{{1}}} | def }}
|
-1b- abc={{{1}}} | -1b- abc={{{1}}} |
{{#if: {{{tst}}} | -1c- abc={{{def}}} | def=ghi }}
|
-1c- abc={{{def}}} | -1c- abc={{{def}}} |
{{#if: {{{tst}}} | -2- {{{1|default}}} }}
|
-2- default | -2- default |
{{#if: {{{tst}}} | -3- {{{2}}} | '''err''' }}
|
-3- {{{2}}} | -3- {{{2}}} |
{{#if: {{{tst}}} | -3b- {{{2|}}} | '''err''' }}
|
-3b- | -3b- |
{{#if: {{{tst}}} | -4- {{{2}}} }}
|
-4- {{{2}}} | -4- {{{2}}} |
[edit] #if: else {{{2}}} anomaly
| Code | Result | ifndef |
|---|---|---|
{{#if: {{ns:0}} |n/a| -1- {{{2}}} }}
|
-1- {{{2}}} | -1- {{{2}}} |
{{#if: {{ns:0}} |n/a| -2- {{{2|default}}} }}
|
-2- default | -2- default |
{{#if: {{ns:0}} |n/a| -3- {{{1}}} }}
|
-3- {{{1}}} | -3- {{{1}}} |
{{#if: {{ns:0}} |n/a| -3b- {{{1|}}} }}
|
-3b- | -3b- |
{{#if: {{ns:0}} |n/a| -4- {{{3}}} }}
|
-4- {{{3}}} | -4- {{{3}}} |
These tables are also available on en:w: for double checking
[edit] #ifexpr variations
| Code | Result | Comment |
|---|---|---|
{{#ifexpr: 42 | -1- {{{1}}} }}
|
-1- {{{1}}} | Same problem as with #if: |
{{#ifexpr: 00 |n/a| -2- {{{1}}} }}
|
-2- {{{1}}} | Same problem as with #if: |
{{#ifexpr: 1 | -3- {{{3|ok}}} |n/a|err}}
|
-3- ok | Undefined default is okay |
{{#ifexpr: 0 |n/a| -4- {{{3}}}|err}}
|
-4- {{{3}}} | Undefined literal corrupted |
{{#ifexpr: 0 |n/a| -5- {{{0}}}}}
|
-5- {{{0}}} | But {{{0}}} is not affected |
[edit] #ifeq variations
| Code | Result | Comment |
|---|---|---|
{{#ifeq: {{{0}}}|{{{0}}}| -1- {{{1}}} }}
|
-1- {{{1}}} | Same problem as with #if: |
{{#ifeq: 1st | 2nd |n/a| -2- {{{1}}} }}
|
-2- {{{1}}} | Same problem as with #if: |
{{#ifeq: | | -3- {{{3|ok}}} |n/a|err}}
|
-3- ok | Undefined default is okay |
{{#ifeq: A | B |n/a| -4- {{{3}}}|err}}
|
-4- {{{3}}} | Undefined literal corrupted |
{{#ifeq: 7 | 007 |-5- {{{1}}} | Bond}}
|
-5- {{{1}}} | Dito with "bug" 5693 |
[edit] Nesting
- {{#if:|p|{{#if:x|a{{{2}}}b|c{{{2}}}d}}}} gives a{{{2}}}b
Apparently, first {{{2}}} is found by counting within the inner #if, but subsequently the bug applies again, now counting from the start (?), and once more, counting within the inner #if again
More, no recursion:
- {{#if:|p|{{#if:x|a{{{2}}}b|c{{{3}}}d}}}} gives a{{{2}}}b
- {{#if:|p|{{#if:x|a{{{1}}}b|c{{{2}}}d}}}} gives a{{{1}}}b
Examples with n nesting levels where the bug for unclear reasons is applied 2^n-1 times:
- {{#if:x|{{#if:x|a{{{1}}}b}}}} gives a{{{1}}}b
- {{#if:x|{{#if:x|{{#if:x|a{{{1}}}b}}}}}} gives a{{{1}}}b
- {{#if:x|{{#if:x|{{#if:x|{{#if:x|a{{{1}}}b}}}}}}}} gives a{{{1}}}b
- {{#if:x|{{#if:x|{{#if:x|{{#if:x|{{#if:x|a{{{1}}}b}}}}}}}}}} gives a{{{1}}}b
- {{#if:||{{#if:||a{{{2}}}b}}}} gives a{{{2}}}b
- {{#if:||{{#if:||{{#if:||a{{{2}}}b}}}}}} gives a{{{2}}}b
- {{#if:||{{#if:||{{#if:||{{#if:||a{{{2}}}b}}}}}}}} gives a{{{2}}}b
- {{#if:||{{#if:||{{#if:||{{#if:||{{#if:||a{{{2}}}b}}}}}}}}}} gives a{{{2}}}b

