Found during the pre-release documentation review (#187).
Problem
A WQL query whose WHERE clause spans several lines is rejected locally with a WqlSyntaxException, although WMI accepts it. Such queries come naturally from Java text blocks or concatenations with \n:
client.wql("""
SELECT Name FROM Win32_Service
WHERE State = 'Running'
AND StartMode = 'Auto'
""").execute(); // WqlSyntaxException, nothing is sent
Checked against the current build (WmiHelper.isValidWql):
| Query |
Accepted |
SELECT Name FROM Win32_Service WHERE State = 'Running' AND StartMode = 'Auto' |
yes |
SELECT Name FROM Win32_Service + \n + WHERE State = 'Running' |
yes |
SELECT Name FROM Win32_Service + \n + WHERE State = 'Running' + \n + AND StartMode = 'Auto' |
no |
Where
WmiHelper.WQL_SIMPLE_SELECT_PATTERN (src/main/java/org/metricshub/winrm/WmiHelper.java) ends with (WHERE\s+.*)?$ and is compiled with Pattern.CASE_INSENSITIVE only. Without Pattern.DOTALL, .* stops at the first line break, so $ cannot match. LightWinRMService.checkWqlArguments uses it for every query, so the legacy WinRMWqlExecutor is affected too.
Expected
Line breaks are accepted anywhere whitespace is, including inside the WHERE clause, probably by adding Pattern.DOTALL, without loosening the grammar otherwise. It stays a single SELECT of * or a property list, FROM one class, and an optional WHERE. ASSOCIATORS OF, REFERENCES OF and event queries stay rejected. Check the legacy WqlQuery parsing for the same issue, and add unit tests for the three cases above.
Found during the pre-release documentation review (#187).
Problem
A WQL query whose
WHEREclause spans several lines is rejected locally with aWqlSyntaxException, although WMI accepts it. Such queries come naturally from Java text blocks or concatenations with\n:Checked against the current build (
WmiHelper.isValidWql):SELECT Name FROM Win32_Service WHERE State = 'Running' AND StartMode = 'Auto'SELECT Name FROM Win32_Service+\n+WHERE State = 'Running'SELECT Name FROM Win32_Service+\n+WHERE State = 'Running'+\n+AND StartMode = 'Auto'Where
WmiHelper.WQL_SIMPLE_SELECT_PATTERN(src/main/java/org/metricshub/winrm/WmiHelper.java) ends with(WHERE\s+.*)?$and is compiled withPattern.CASE_INSENSITIVEonly. WithoutPattern.DOTALL,.*stops at the first line break, so$cannot match.LightWinRMService.checkWqlArgumentsuses it for every query, so the legacyWinRMWqlExecutoris affected too.Expected
Line breaks are accepted anywhere whitespace is, including inside the
WHEREclause, probably by addingPattern.DOTALL, without loosening the grammar otherwise. It stays a singleSELECTof*or a property list,FROMone class, and an optionalWHERE.ASSOCIATORS OF,REFERENCES OFand event queries stay rejected. Check the legacyWqlQueryparsing for the same issue, and add unit tests for the three cases above.