Skip to content

Commit a9152cb

Browse files
committed
[TASK] Add tests and adjust ambiguity in AstConstantCommentVisitor
The `AstConstantCommentVisitor` is used to parse `ext_conf_template.txt` files of extensions. The file provides TypoScript comments which are parsed as constants to allow GUI configuration mapping in the TypoScript Constant Editor. A comment string like this: ``` # cat=Integer/101/15; type=int[-5--1]; label=Int 6 - range (neg start, neg end) ``` is parsed as syntax (yes, yuck) and specifically the argument `type=int[-5--1]` is tokenized and parsed into a min/max range. This was performed with ambiguous interpretation with `$start/$stop` temporary variables and character-by-character parsing to find out if a number is positive or negative. The old comparison: ``` } elseif ($stop === '' && $char === '-') { ``` was never possible to trigger though, because $stop was initialized as 'null'. This only worked before strict type declarations where enabled in legacy code, likely. Funnily, this oddity had no real-life implications as the newly added tests reveal. Before this patch, `$negativeStop` could never be set to `true`, thus the later code: ``` if ($negativeStop) { $stop = (int)$stop * -1; } ``` was never triggered. So a value like `1` (from `-5--1`) would not be transformed into `-1` theoretically. Luckily though, in this case `$stop` was already set to `-1` (note that it would be a TWO character string then). When fixing this code to use a proper `$stop === null` comparison, the end result is still the same, and `$stop` will be set to `-1`. Tests verify that the behaviour is the same before and after the patch. With this patch, PHPStan will no longer report the condition to be unused, unlocking an update to PHPStan 2.1.19 without a change in the baseline. Resolves: #107125 Related: #98357 Related: #97816 Releases: main, 13.4 Change-Id: I6067fec7357dda1533e180f157ddd70c86ea9800 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/90112 Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: Garvin Hicking <garvin@hick.ing> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Garvin Hicking <garvin@hick.ing> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
1 parent c781a30 commit a9152cb

File tree

3 files changed

+1090
-1
lines changed

3 files changed

+1090
-1
lines changed

typo3/sysext/core/Classes/TypoScript/AST/Visitor/AstConstantCommentVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private function parseNodeComment(TokenStreamInterface $commentTokenStream, stri
284284
$gotSeparatorDash = true;
285285
} elseif (!$gotSeparatorDash) {
286286
$start .= $char;
287-
} elseif ($stop === '' && $char === '-') {
287+
} elseif ($stop === null && $char === '-') {
288288
$negativeStop = true;
289289
} else {
290290
$stop .= $char;
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
############################
2+
### CUSTOM SUBCATEGORIES ###
3+
###########################
4+
# customsubcategory=100=Boolean
5+
# customsubcategory=101=Int
6+
# customsubcategory=102=Int+
7+
# customsubcategory=200=String
8+
# customsubcategory=201=Small
9+
# customsubcategory=202=Wrap
10+
# customsubcategory=300=Offset
11+
# customsubcategory=400=Color
12+
# customsubcategory=500=User
13+
# customsubcategory=600=Options
14+
# customsubcategory=900=Input
15+
# customsubcategory=901=Default
16+
17+
18+
############
19+
### Text ###
20+
############
21+
22+
# cat=Text/200/10; type=string; label=String 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
23+
string_1 = value
24+
# cat=Text/200/11; type=string; label=String 2 - no value
25+
string_2 =
26+
27+
# cat=Text/201/10; type=small; label=Small 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
28+
small_1 = value
29+
# cat=Text/201/11; type=small; label=Small 2 - no value
30+
small_2 =
31+
32+
# cat=Text/202/10; type=wrap; label=Wrap 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
33+
wrap_1 = value
34+
# cat=Text/202/11; type=wrap; label=Wrap 2 - no value
35+
wrap_2 =
36+
37+
38+
#############
39+
### Color ###
40+
#############
41+
42+
# cat=Color/400/10; type=color; label=Color 1 - value black
43+
color_1 = black
44+
45+
# cat=Color/400/11; type=color; label=Color 2 - value #000000
46+
color_2 = #000000
47+
48+
# cat=Color/400/12; type=color; label=Color 3 - value 000000
49+
color_3 = 000000
50+
51+
# cat=Color/400/13; type=color; label=Color 4 - no value
52+
color_4 =
53+
54+
55+
##############
56+
### Offset ###
57+
##############
58+
59+
# cat=Offset/300/10; type=offset; label=Offset 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
60+
offset_1 = x,y
61+
# cat=Offset/300/11; type=offset; label=Offset 2 - value x
62+
offset_2 = x
63+
# cat=Offset/300/12; type=offset; label=Offset 2 - value y
64+
offset_3 = ,y
65+
# cat=Offset/300/13; type=offset; label=Offset 2 - no value
66+
offset_4 =
67+
68+
69+
############
70+
### User ###
71+
############
72+
73+
# cat=User/500/10; type=user[TYPO3\CMS\Styleguide\UserFunctions\ExtensionConfiguration\User1->user_1]; label=User - display params
74+
user_1 = 0
75+
76+
77+
###############
78+
### Options ###
79+
###############
80+
81+
# cat=Options/600/10; type=options[Default=default, Option 1=option_1, Option 2=option_2, Option 3=option_3]; label=Option - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
82+
options_1 = default
83+
# cat=Options/600/11; type=options[Default=default, Option 1=option_1, Option 2=option_2, Option 3=option_3]; label=Option - default option_2
84+
options_2 = option_2
85+
# cat=Options/600/11; type=options[Default=default, Option 1=option_1, Option 2=option_2, Option 3=option_3]; label=Option - no default
86+
options_3 =
87+
88+
89+
###############
90+
### Boolean ###
91+
###############
92+
93+
# cat=Boolean/100/10; type=boolean; label=Boolean 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
94+
boolean_1 = 0
95+
# cat=Boolean/100/11; type=boolean; label=Boolean 2 - checked
96+
boolean_2 = 1
97+
# cat=Boolean/100/12; type=boolean; label=Boolean 3 - no value
98+
boolean_3 =
99+
# cat=Boolean/100/13; type=boolean[myTrueValue]; label=Boolean 4 - different bool value
100+
boolean_4 = 0
101+
102+
103+
################
104+
### Integers ###
105+
################
106+
107+
# cat=Integer/101/10; type=int; label=Int 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
108+
int_1 = 1
109+
# cat=Integer/101/11; type=int; label=Int 2 - no value
110+
int_2 =
111+
# cat=Integer/101/12; type=int; label=Int 3 - negative value
112+
int_3 = -100
113+
# cat=Integer/101/13; type=int[1-5]; label=Int 4 - range (pos start, pos end)
114+
int_4 = 2
115+
# cat=Integer/101/14; type=int[-5-5]; label=Int 5 - range (neg start, pos end)
116+
int_5 = 2
117+
# cat=Integer/101/15; type=int[-5--1]; label=Int 6 - range (neg start, neg end)
118+
int_6 = 2
119+
# cat=Integer/101/16; type=int[1--5]; label=Int 7 - range (pos start, neg end)
120+
int_7 = 2
121+
# cat=Integer/101/17; type=int[--5]; label=Int 8 - range (neg end)
122+
int_8 = 2
123+
124+
# cat=Integer/102/10; type=int+; label=Int+ 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
125+
intplus_1 = 1
126+
# cat=Integer/102/11; type=int+; label=Int+ 2 - no value
127+
intplus_2 =
128+
# cat=Integer/101/12; type=int+[1-5]; label=Int+ 3 - range
129+
intplus_3 = 2
130+
131+
132+
133+
#####################
134+
### Compatibility ###
135+
#####################
136+
137+
# cat=Compatibility/900/10; type=input; label=Input 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
138+
compat_input_1 = value
139+
# cat=Compatibility/900/11; type=input; label=Input 2 - no value
140+
compat_input_2 =
141+
142+
# cat=Compatibility/901/10; type=default; label=Input 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
143+
compat_default_1 = value
144+
# cat=Compatibility/901/11; type=default; label=Input 2 - no value
145+
compat_default_2 =
146+
147+
##########################
148+
### Zero-indexed order ###
149+
##########################
150+
151+
# cat=ZeroIndex//0; type=input; label=Input 1 - help text:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel sollicitudin odio.
152+
zeroorder_input_1 = value
153+
# cat=ZeroIndex//2; type=input; label=Input 3 - no value
154+
zeroorder_input_3 =
155+
# cat=ZeroIndex//1; type=input; label=Input 2 - no value
156+
zeroorder_input_2 =
157+
158+
##########################
159+
### Nested declaration ###
160+
##########################
161+
162+
nested {
163+
# cat=Nested; type=input; label=Input 1
164+
input_1 = aDefault
165+
# cat=Nested; type=input; label=Input 2
166+
input_2 =
167+
}
168+
169+
##################################
170+
### Pre defined sub categories ###
171+
##################################
172+
173+
# cat=Pre defined/dims/10; type=int; label=Input 1
174+
predefined.int_1 = 42
175+
176+
# cat=Pre defined/enable/10; type=boolean; label=LLL:EXT:styleguide/Resources/Private/Language/locallang.xlf:extConfTemplateLocalizedLabel
177+
predefined.boolean_1 = 1

0 commit comments

Comments
 (0)