Skip to content

Commit a8b36c7

Browse files
authored
Fix windows version validator under Chinese (#116282)
* Fix windows version validator under Chinese * Update authors * Update RegExp to reduce groups * Add a trailing newline
1 parent 09d4893 commit a8b36c7

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ Nguyễn Phúc Lợi <[email protected]>
9999
Jingyi Chen <[email protected]>
100100
Junhua Lin <[email protected]>
101101
Tomasz Gucio <[email protected]>
102+
Jason C.H <[email protected]>

packages/flutter_tools/lib/src/windows/windows_version_validator.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const List<String> kUnsupportedVersions = <String>[
1717
/// Regex pattern for identifying line from systeminfo stdout with windows version
1818
/// (ie. 10.5.4123)
1919
const String kWindowsOSVersionSemVerPattern =
20-
r'^(OS Version:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)$';
20+
r'^(OS )([^:]*:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)$';
2121

2222
/// Validator for supported Windows host machine operating system version.
2323
class WindowsVersionValidator extends DoctorValidator {
@@ -52,7 +52,7 @@ class WindowsVersionValidator extends DoctorValidator {
5252
final String statusInfo;
5353
if (matches.length == 1 &&
5454
!kUnsupportedVersions
55-
.contains(matches.elementAt(0).group(2)?.split('.').elementAt(0))) {
55+
.contains(matches.elementAt(0).group(3)?.split('.').elementAt(0))) {
5656
windowsVersionStatus = ValidationType.installed;
5757
statusInfo = 'Installed version of Windows is version 10 or higher';
5858
} else {

packages/flutter_tools/test/general.shard/windows_version_validator_test.dart

+79-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,45 @@ Hotfix(s): 7 Hotfix(s) Installed.
5252
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
5353
''';
5454

55+
const String validWindows11CnStdOut = r'''
56+
主机名: XXXXXXXXXXXX
57+
OS 名称: Microsoft Windows 11 专业版
58+
OS 版本: 10.0.22621 暂缺 Build 22621
59+
OS 制造商: Microsoft Corporation
60+
OS 配置: 独立工作站
61+
OS 构建类型: Multiprocessor Free
62+
注册的所有人: 暂缺
63+
注册的组织: 暂缺
64+
产品 ID: XXXXXXXXXXXX
65+
初始安装日期: 2022/11/9, 13:33:50
66+
系统启动时间: 2022/11/30, 13:36:47
67+
系统制造商: ASUS
68+
系统型号: System Product Name
69+
系统类型: x64-based PC
70+
处理器: 安装了 1 个处理器。
71+
[01]: Intel64 Family 6 Model 151 Stepping 2 GenuineIntel ~3600 Mhz
72+
BIOS 版本: American Megatrends Inc. 2103, 2022/9/30
73+
Windows 目录: C:\WINDOWS
74+
系统目录: C:\WINDOWS\system32
75+
启动设备: \Device\HarddiskVolume1
76+
系统区域设置: zh-cn;中文(中国)
77+
输入法区域设置: zh-cn;中文(中国)
78+
时区: (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐
79+
物理内存总量: 65,277 MB
80+
可用的物理内存: 55,333 MB
81+
虚拟内存: 最大值: 75,005 MB
82+
虚拟内存: 可用: 61,781 MB
83+
虚拟内存: 使用中: 13,224 MB
84+
页面文件位置: C:\pagefile.sys
85+
域: WORKGROUP
86+
登录服务器: \\XXXXXXXXXXXX
87+
修补程序: 安装了 3 个修补程序。
88+
[01]: KB5020622
89+
[02]: KB5019980
90+
[03]: KB5019304
91+
Hyper-V 要求: 已检测到虚拟机监控程序。将不显示 Hyper-V 所需的功能。
92+
''';
93+
5594
/// Example output from `systeminfo` from version != 10
5695
const String invalidWindowsStdOut = r'''
5796
Host Name: XXXXXXXXXXXX
@@ -151,6 +190,36 @@ void main() {
151190
reason: 'The ValidationResult statusInfo messages should be the same');
152191
});
153192

193+
testWithoutContext(
194+
'Successfully running windows version check on windows 11 CN',
195+
() async {
196+
final WindowsVersionValidator windowsVersionValidator =
197+
WindowsVersionValidator(
198+
processManager: FakeProcessManager.list(
199+
<FakeCommand>[
200+
const FakeCommand(
201+
command: <String>['systeminfo'],
202+
stdout: validWindows11CnStdOut,
203+
),
204+
],
205+
),
206+
);
207+
208+
final ValidationResult result = await windowsVersionValidator.validate();
209+
210+
expect(
211+
result.type,
212+
validWindows10ValidationResult.type,
213+
reason: 'The ValidationResult type should be the same (installed)',
214+
);
215+
expect(
216+
result.statusInfo,
217+
validWindows10ValidationResult.statusInfo,
218+
reason: 'The ValidationResult statusInfo messages should be the same',
219+
);
220+
},
221+
);
222+
154223
testWithoutContext('Failing to invoke the `systeminfo` command', () async {
155224
final WindowsVersionValidator windowsVersionValidator =
156225
WindowsVersionValidator(
@@ -217,19 +286,24 @@ void main() {
217286
const String testStr = r'''
218287
OS Version: 10.0.19044 N/A Build 19044
219288
OSz Version: 10.0.19044 N/A Build 19044
220-
OS 6Version: 10.0.19044 N/A Build 19044
221289
OxS Version: 10.0.19044 N/A Build 19044
222290
OS Version: 10.19044 N/A Build 19044
223291
OS Version: 10.x.19044 N/A Build 19044
224292
OS Version: 10.0.19044 N/A Build 19044
225293
OS Version: .0.19044 N/A Build 19044
294+
OS 版本: 10.0.22621 暂缺 Build 22621
226295
''';
227296

228-
final RegExp regex =
229-
RegExp(kWindowsOSVersionSemVerPattern, multiLine: true);
297+
final RegExp regex = RegExp(
298+
kWindowsOSVersionSemVerPattern,
299+
multiLine: true,
300+
);
230301
final Iterable<RegExpMatch> matches = regex.allMatches(testStr);
231302

232-
expect(matches.length, 2,
233-
reason: 'There should be only two matches for the pattern provided');
303+
expect(
304+
matches.length,
305+
3,
306+
reason: 'There should be only two matches for the pattern provided',
307+
);
234308
});
235309
}

0 commit comments

Comments
 (0)