[FIX] hw_drivers: sanitize keyboard devices name
To reproduce: Synchronise an IoT-box with a device with `\x00` characters in its name => ERROR: bad query: UPDATE "iot_device" SET "name"=%s WHERE id IN %s ERROR: A string literal cannot contain NUL (0x00) characters. Note that this is pretty rare to have this characters in devices names. But it looks to happen with some Chinese devices like the "TaoTronics 2-in-1 Bluetooth & Wired Barcode Scanner USB Portable Bar Code Scanner" OPW-2748580 closes odoo/odoo#90018 X-original-commit: 5a94d445f1183f256d7847b332b86c81bb711854 Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from lxml import etree
|
||||
import os
|
||||
from pathlib import Path
|
||||
from queue import Queue, Empty
|
||||
import re
|
||||
import subprocess
|
||||
from threading import Lock
|
||||
import time
|
||||
@@ -118,7 +119,7 @@ class KeyboardUSBDriver(Driver):
|
||||
try:
|
||||
manufacturer = util.get_string(self.dev, self.dev.iManufacturer)
|
||||
product = util.get_string(self.dev, self.dev.iProduct)
|
||||
return ("%s - %s") % (manufacturer, product)
|
||||
return re.sub(r"[^\w \-+/*&]", '', "%s - %s" % (manufacturer, product))
|
||||
except ValueError as e:
|
||||
_logger.warning(e)
|
||||
return _('Unknown input device')
|
||||
|
||||
Reference in New Issue
Block a user