mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
hwdb: fix check for uppercasedness of match patterns
The check was added in 77547d5313
, but
it doesn't work as expected. Because the second part is wrapped in Optional(),
it would silently "succeed" when the lowercase digits were in the second part:
>>> from parse_hwdb import *
>>> g = 'v' + upperhex_word(4) + Optional('p' + upperhex_word(4))
>>> g.parseString('v04D8pE11C*')
(['v', '04D8', 'p', 'E11C'], {})
>>> g.parseString('v04D8pe11c*')
(['v', '04D8'], {})
The following matches are OK:
usb:v0627p0001:*QEMU USB Keyboard*
usb:v0627p0001:*
usb:v0627p0001*
usb:v0627*
This commit is contained in:
parent
1341f25b9b
commit
1a37237e2f
@ -212,21 +212,23 @@ def check_matches(groups):
|
||||
|
||||
# This is a partial check. The other cases could be also done, but those
|
||||
# two are most commonly wrong.
|
||||
grammars = { 'usb' : 'v' + upperhex_word(4) + Optional('p' + upperhex_word(4)),
|
||||
'pci' : 'v' + upperhex_word(8) + Optional('d' + upperhex_word(8)),
|
||||
grammars = { 'usb' : 'v' + upperhex_word(4) + Optional('p' + upperhex_word(4) + Optional(':')) + '*',
|
||||
'pci' : 'v' + upperhex_word(8) + Optional('d' + upperhex_word(8) + Optional(':')) + '*',
|
||||
}
|
||||
|
||||
for match in matches:
|
||||
prefix, rest = match.split(':', maxsplit=1)
|
||||
gr = grammars.get(prefix)
|
||||
if gr:
|
||||
# we check this first to provide an easy error message
|
||||
if rest[-1] not in '*:':
|
||||
error('pattern {} does not end with "*" or ":"', match)
|
||||
|
||||
try:
|
||||
gr.parseString(rest)
|
||||
except ParseBaseException as e:
|
||||
error('Pattern {!r} is invalid: {}', rest, e)
|
||||
continue
|
||||
if rest[-1] not in '*:':
|
||||
error('pattern {} does not end with "*" or ":"', match)
|
||||
|
||||
matches.sort()
|
||||
prev = None
|
||||
|
Loading…
Reference in New Issue
Block a user